Berland.Taxi is a new taxi company with k cars which started operating in the capital of Berland just recently. The capital has n houses on a straight line numbered from 1 (leftmost) to n (rightmost), and the distance between any two neighboring houses is the same.

You have to help the company schedule all the taxi rides which come throughout the day according to the following rules: 

  * All cars are available for picking up passengers. Initially the j-th car is located next to the house with the number xj at time 0. 
  * All cars have the same speed. It takes exactly 1 minute for any car to travel between neighboring houses i and i + 1. 
  * The i-th request for taxi ride comes at the time ti, asking for a passenger to be picked up at the house ai and dropped off at the house bi. All requests for taxi rides are given in the increasing order of ti. All ti are distinct. 



When a request for taxi ride is received at time ti, Berland.Taxi operator assigns a car to it as follows: 

  * Out of cars which are currently available, operator assigns the car which is the closest to the pick up spot ai. Needless to say, if a car is already on a ride with a passenger, it won't be available for any rides until that passenger is dropped off at the corresponding destination. 
  * If there are several such cars, operator will pick one of them which has been waiting the most since it became available. 
  * If there are several such cars, operator will pick one of them which has the lowest number. 



After a car gets assigned to the taxi ride request: 

  * The driver immediately starts driving from current position to the house ai. 
  * Once the car reaches house ai, the passenger is immediately picked up and the driver starts driving to house bi. 
  * Once house bi is reached, the passenger gets dropped off and the car becomes available for new rides staying next to the house bi. 
  * It is allowed for multiple cars to be located next to the same house at the same point in time, while waiting for ride requests or just passing by. 



If there are no available cars at time ti when a request for taxi ride comes, then: 

  * The i-th passenger will have to wait for a car to become available. 
  * When a car becomes available, operator will immediately assign it to this taxi ride request. 
  * If multiple cars become available at once while the passenger is waiting, operator will pick a car out of them according to the rules described above. 



Operator processes taxi ride requests one by one. So if multiple passengers are waiting for the cars to become available, operator will not move on to processing the (i + 1)-th ride request until the car gets assigned to the i-th ride request.

Your task is to write a program that will process the given list of m taxi ride requests. For each request you have to find out which car will get assigned to it, and how long the passenger will have to wait for a car to arrive. Note, if there is already car located at the house ai, then the corresponding wait time will be 0.

Input

The first line of input contains integers n, k and m (2 ≤ n ≤ 2·105, 1 ≤ k, m ≤ 2·105) — number of houses, number of cars, and number of taxi ride requests. The second line contains integers x1, x2, ..., xk (1 ≤ xi ≤ n) — initial positions of cars. xi is a house number at which the i-th car is located initially. It's allowed for more than one car to be located next to the same house.

The following m lines contain information about ride requests. Each ride request is represented by integers tj, aj and bj (1 ≤ tj ≤ 1012, 1 ≤ aj, bj ≤ n, aj ≠ bj), where tj is time in minutes when a request is made, aj is a house where passenger needs to be picked up, and bj is a house where passenger needs to be dropped off. All taxi ride requests are given in the increasing order of tj. All tj are distinct.

Output

Print m lines: the j-th line should contain two integer numbers, the answer for the j-th ride request — car number assigned by the operator and passenger wait time.

Examples

Input

10 1 2
3
5 2 8
9 10 3


Output

1 1
1 5


Input

5 2 1
1 5
10 3 5


Output

1 2


Input

5 2 2
1 5
10 3 5
20 4 1


Output

1 2
2 1

Note

In the first sample test, a request comes in at time 5 and the car needs to get from house 3 to house 2 to pick up the passenger. Therefore wait time will be 1 and the ride will be completed at time 5 + 1 + 6 = 12. The second request comes in at time 9, so the passenger will have to wait for the car to become available at time 12, and then the car needs another 2 minutes to get from house 8 to house 10. So the total wait time is 3 + 2 = 5. 

In the second sample test, cars 1 and 2 are located at the same distance from the first passenger and have the same "wait time since it became available". Car 1 wins a tiebreaker according to the rules because it has the lowest number. It will come to house 3 at time 3, so the wait time will be 2.
#include <bits/stdc++.h>
using namespace std;
multiset<int> W;
set<pair<long long, long long> > S[200020];
struct str {
  str() {}
  str(long long tm, int c, int b) : tm(tm), c(c), b(b) {}
  long long tm;
  int c, b;
  bool operator>(const str &rhs) const { return tm > rhs.tm; }
};
priority_queue<str, vector<str>, greater<str> > pq;
void solve() {
  int n, k, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= k; i++) {
    int x;
    scanf("%d", &x);
    S[x].insert(pair<long long, long long>(0, i));
    W.insert(x);
  }
  long long fm = 0;
  for (int i = 1; i <= m; i++) {
    long long t;
    int a, b;
    scanf("%lld%d%d", &t, &a, &b);
    fm = max(fm, t);
    while (!pq.empty() && pq.top().tm <= fm) {
      auto e = pq.top();
      pq.pop();
      W.insert(e.b);
      S[e.b].insert(pair<long long, long long>(e.tm, e.c));
    }
    if (((int)(W).size()) == 0) {
      fm = pq.top().tm;
      while (!pq.empty() && pq.top().tm == fm) {
        auto e = pq.top();
        pq.pop();
        W.insert(e.b);
        S[e.b].insert(pair<long long, long long>(e.tm, e.c));
      }
    }
    auto it = W.lower_bound(a);
    int idis = 1e9, jdis = 1e9;
    if (it != W.end()) idis = *it - a;
    auto jt = it;
    if (it != W.begin()) jt = prev(it), jdis = a - *jt;
    pair<long long, long long> tex = pair<long long, long long>(-1, -1);
    if (idis < jdis || (idis == jdis && *S[*it].begin() < *S[*jt].begin())) {
      tex = *S[*it].begin();
      S[*it].erase(S[*it].begin());
      W.erase(it);
      long long det = fm + idis + abs(a - b);
      pq.push(str(det, (int)tex.second, b));
      printf("%d %lld\n", (int)tex.second, fm + idis - t);
    } else {
      tex = *S[*jt].begin();
      S[*jt].erase(S[*jt].begin());
      W.erase(jt);
      long long det = fm + jdis + abs(a - b);
      pq.push(str(det, (int)tex.second, b));
      printf("%d %lld\n", (int)tex.second, fm + jdis - t);
    }
  }
}
int main() {
  int Tc = 1;
  for (int tc = 1; tc <= Tc; tc++) {
    solve();
  }
  return 0;
}
