#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
struct Edge {
  long long a;
  long long b;
  long long c;
  long long t;
  bool operator<(const Edge &other) const { return c < other.c; }
};
long long n, q;
long long arr[N];
long long ord[N];
long long ids[N];
long long mxi[N];
long long bst[N];
long long pre[N];
long long dep[N];
long long val[N][20];
long long tbl[N][20];
pair<long long, long long> que[N];
pair<long long, long long> ans[N];
vector<pair<long long, long long>> con[N];
long long get(long long u, long long v) {
  if (dep[u] > dep[v]) swap(u, v);
  long long dis = dep[v] - dep[u];
  long long res = 0;
  for (long long i = 19; i >= 0; i--) {
    if (dis >> i & 1) {
      res = max(res, val[v][i]);
      v = tbl[v][i];
    }
  }
  if (u == v) return res;
  for (long long i = 19; i >= 0; i--) {
    if (tbl[v][i] != tbl[u][i]) {
      res = max(res, val[v][i]);
      res = max(res, val[u][i]);
      v = tbl[v][i];
      u = tbl[u][i];
    }
  }
  res = max(res, val[v][0]);
  res = max(res, val[u][0]);
  return res;
}
long long fnd(long long i) {
  if (ids[i] != i) ids[i] = fnd(ids[i]);
  return ids[i];
}
void unn(long long a, long long b) {
  a = fnd(a);
  b = fnd(b);
  if (arr[bst[b]] > arr[bst[a]]) {
    swap(a, b);
  } else if (arr[bst[a]] == arr[bst[b]]) {
    mxi[a] = max(get(bst[a], bst[b]), max(mxi[a], mxi[b]));
  }
  ids[b] = a;
}
void dfs(long long i, long long p, long long x, long long d) {
  pre[i] = p;
  dep[i] = d;
  tbl[i][0] = p;
  val[i][0] = x;
  for (long long h = 1; h <= 19; h++) {
    tbl[i][h] = tbl[tbl[i][h - 1]][h - 1];
    val[i][h] = max(val[i][h - 1], val[tbl[i][h - 1]][h - 1]);
  }
  for (auto [v, t] : con[i]) {
    if (v != p) {
      dfs(v, i, t, d + 1);
    }
  }
}
bool cmp(long long a, long long b) { return que[a].first > que[b].first; }
signed main() {
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  vector<Edge> edges;
  for (long long i = 2; i <= n; i++) {
    Edge e;
    cin >> e.a >> e.b >> e.c >> e.t;
    con[e.a].emplace_back(e.b, e.t);
    con[e.b].emplace_back(e.a, e.t);
    edges.push_back(e);
  }
  dfs(1, 0, 0, 0);
  sort(begin(edges), end(edges));
  for (long long i = 1; i <= q; i++) {
    cin >> que[i].first >> que[i].second;
  }
  iota(ord + 1, ord + 1 + q, 1);
  sort(ord + 1, ord + 1 + q, cmp);
  iota(ids + 1, ids + 1 + n, 1);
  iota(bst + 1, bst + 1 + n, 1);
  long long idx = n - 2;
  for (long long i = 1; i <= q; i++) {
    long long j = ord[i];
    while (idx >= 0 && edges[idx].c >= que[j].first) {
      unn(edges[idx].a, edges[idx].b), idx--;
    }
    long long p = que[j].second;
    long long r = max(get(p, bst[fnd(p)]), mxi[fnd(p)]);
    ans[j] = make_pair(arr[bst[fnd(p)]], r);
  }
  for (long long i = 1; i <= q; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}

### Prompt

Your task is to create a cpp solution to the following problem:

Omkar is hosting tours of his country, Omkarland! There are n cities in Omkarland, and, rather curiously, there are exactly n-1 bidirectional roads connecting the cities to each other. It is guaranteed that you can reach any city from any other city through the road network.

Every city has an enjoyment value e. Each road has a capacity c, denoting the maximum number of vehicles that can be on it, and an associated toll t. However, the toll system in Omkarland has an interesting quirk: if a vehicle travels on multiple roads on a single journey, they pay only the highest toll of any single road on which they traveled. (In other words, they pay max t over all the roads on which they traveled.) If a vehicle traverses no roads, they pay 0 toll.

Omkar has decided to host q tour groups. Each tour group consists of v vehicles starting at city x. (Keep in mind that a tour group with v vehicles can travel only on roads with capacity ≥ v.) Being the tour organizer, Omkar wants his groups to have as much fun as they possibly can, but also must reimburse his groups for the tolls that they have to pay. Thus, for each tour group, Omkar wants to know two things: first, what is the enjoyment value of the city y with maximum enjoyment value that the tour group can reach from their starting city, and second, how much per vehicle will Omkar have to pay to reimburse the entire group for their trip from x to y? (This trip from x to y will always be on the shortest path from x to y.)

In the case that there are multiple reachable cities with the maximum enjoyment value, Omkar will let his tour group choose which one they want to go to. Therefore, to prepare for all possible scenarios, he wants to know the amount of money per vehicle that he needs to guarantee that he can reimburse the group regardless of which city they choose.

Input

The first line contains two integers n and q (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5), representing the number of cities and the number of groups, respectively.

The next line contains n integers e_1, e_2, …, e_n (1 ≤ e_i ≤ 10^9), where e_i represents the enjoyment value for city i.

The next n-1 lines each contain four integers a, b, c, and t (1 ≤ a,b ≤ n, 1 ≤ c ≤ 10^9, 1 ≤ t ≤ 10^9), representing an road between city a and city b with capacity c and toll t.

The next q lines each contain two integers v and x (1 ≤ v ≤ 10^9, 1 ≤ x ≤ n), representing the number of vehicles in the tour group and the starting city, respectively.

Output

Output q lines. The i-th line should contain two integers: the highest possible enjoyment value of a city reachable by the i-th tour group, and the amount of money per vehicle Omkar needs to guarantee that he can reimburse the i-th tour group.

Examples

Input


5 3
2 2 3 3 3
1 2 4 7
1 3 2 8
2 4 8 2
2 5 1 1
1 3
9 5
6 2


Output


3 8
3 0
3 2


Input


5 5
1 2 3 4 5
1 2 4 1
1 3 3 1
1 4 2 1
2 5 1 1
5 1
4 1
3 1
2 1
1 1


Output


1 0
2 1
3 1
4 1
5 1


Input


5 5
1 2 2 2 2
1 2 5 8
1 3 6 3
1 4 4 5
1 5 7 1
4 1
5 1
6 1
7 1
8 1


Output


2 8
2 8
2 3
2 1
1 0

Note

A map of the first sample is shown below. For the nodes, unbolded numbers represent indices and bolded numbers represent enjoyment values. For the edges, unbolded numbers represent capacities and bolded numbers represent tolls.

<image>

For the first query, a tour group of size 1 starting at city 3 can reach cities 1, 2, 3, 4, and 5. Thus, the largest enjoyment value that they can reach is 3. If the tour group chooses to go to city 4, Omkar will have to pay 8 per vehicle, which is the maximum.

For the second query, a tour group of size 9 starting at city 5 can reach only city 5. Thus, the largest reachable enjoyment value is still 3, and Omkar will pay 0 per vehicle.

For the third query, a tour group of size 6 starting at city 2 can reach cities 2 and 4. The largest reachable enjoyment value is again 3. If the tour group chooses to go to city 4, Omkar will have to pay 2 per vehicle, which is the maximum.

A map of the second sample is shown below:

<image>

For the first query, a tour group of size 5 starting at city 1 can only reach city 1. Thus, their maximum enjoyment value is 1 and the cost Omkar will have to pay is 0 per vehicle.

For the second query, a tour group of size 4 starting at city 1 can reach cities 1 and 2. Thus, their maximum enjoyment value is 2 and Omkar will pay 1 per vehicle.

For the third query, a tour group of size 3 starting at city 1 can reach cities 1, 2, and 3. Thus, their maximum enjoyment value is 3 and Omkar will pay 1 per vehicle.

For the fourth query, a tour group of size 2 starting at city 1 can reach cities 1, 2, 3 and 4. Thus, their maximum enjoyment value is 4 and Omkar will pay 1 per vehicle.

For the fifth query, a tour group of size 1 starting at city 1 can reach cities 1, 2, 3, 4, and 5. Thus, their maximum enjoyment value is 5 and Omkar will pay 1 per vehicle.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1;
struct Edge {
  long long a;
  long long b;
  long long c;
  long long t;
  bool operator<(const Edge &other) const { return c < other.c; }
};
long long n, q;
long long arr[N];
long long ord[N];
long long ids[N];
long long mxi[N];
long long bst[N];
long long pre[N];
long long dep[N];
long long val[N][20];
long long tbl[N][20];
pair<long long, long long> que[N];
pair<long long, long long> ans[N];
vector<pair<long long, long long>> con[N];
long long get(long long u, long long v) {
  if (dep[u] > dep[v]) swap(u, v);
  long long dis = dep[v] - dep[u];
  long long res = 0;
  for (long long i = 19; i >= 0; i--) {
    if (dis >> i & 1) {
      res = max(res, val[v][i]);
      v = tbl[v][i];
    }
  }
  if (u == v) return res;
  for (long long i = 19; i >= 0; i--) {
    if (tbl[v][i] != tbl[u][i]) {
      res = max(res, val[v][i]);
      res = max(res, val[u][i]);
      v = tbl[v][i];
      u = tbl[u][i];
    }
  }
  res = max(res, val[v][0]);
  res = max(res, val[u][0]);
  return res;
}
long long fnd(long long i) {
  if (ids[i] != i) ids[i] = fnd(ids[i]);
  return ids[i];
}
void unn(long long a, long long b) {
  a = fnd(a);
  b = fnd(b);
  if (arr[bst[b]] > arr[bst[a]]) {
    swap(a, b);
  } else if (arr[bst[a]] == arr[bst[b]]) {
    mxi[a] = max(get(bst[a], bst[b]), max(mxi[a], mxi[b]));
  }
  ids[b] = a;
}
void dfs(long long i, long long p, long long x, long long d) {
  pre[i] = p;
  dep[i] = d;
  tbl[i][0] = p;
  val[i][0] = x;
  for (long long h = 1; h <= 19; h++) {
    tbl[i][h] = tbl[tbl[i][h - 1]][h - 1];
    val[i][h] = max(val[i][h - 1], val[tbl[i][h - 1]][h - 1]);
  }
  for (auto [v, t] : con[i]) {
    if (v != p) {
      dfs(v, i, t, d + 1);
    }
  }
}
bool cmp(long long a, long long b) { return que[a].first > que[b].first; }
signed main() {
  cin >> n >> q;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  vector<Edge> edges;
  for (long long i = 2; i <= n; i++) {
    Edge e;
    cin >> e.a >> e.b >> e.c >> e.t;
    con[e.a].emplace_back(e.b, e.t);
    con[e.b].emplace_back(e.a, e.t);
    edges.push_back(e);
  }
  dfs(1, 0, 0, 0);
  sort(begin(edges), end(edges));
  for (long long i = 1; i <= q; i++) {
    cin >> que[i].first >> que[i].second;
  }
  iota(ord + 1, ord + 1 + q, 1);
  sort(ord + 1, ord + 1 + q, cmp);
  iota(ids + 1, ids + 1 + n, 1);
  iota(bst + 1, bst + 1 + n, 1);
  long long idx = n - 2;
  for (long long i = 1; i <= q; i++) {
    long long j = ord[i];
    while (idx >= 0 && edges[idx].c >= que[j].first) {
      unn(edges[idx].a, edges[idx].b), idx--;
    }
    long long p = que[j].second;
    long long r = max(get(p, bst[fnd(p)]), mxi[fnd(p)]);
    ans[j] = make_pair(arr[bst[fnd(p)]], r);
  }
  for (long long i = 1; i <= q; i++)
    cout << ans[i].first << " " << ans[i].second << "\n";
}

```