Problem: Misha has a tree with characters written on the vertices. He can choose two vertices s and t of this tree and write down characters of vertices lying on a path from s to t. We'll say that such string corresponds to pair (s, t).

Misha has m queries of type: you are given 4 vertices a, b, c, d; you need to find the largest common prefix of the strings that correspond to pairs (a, b) and (c, d). Your task is to help him.

Input

The first line contains integer n (1 ≤ n ≤ 300 000) — the number of vertices in the tree.

Next follows a line consisting of n small English letters. The i-th character of the string corresponds to the character written on the i-th vertex. 

Next n - 1 lines contain information about edges. An edge is defined by a pair of integers u, v (1 ≤ u, v ≤ n, u ≠ v), separated by spaces.

The next line contains integer m (1 ≤ m ≤ 1 000 000) — the number of queries.

Next m lines contain information about queries. A query is defined by four integers a, b, c, d (1 ≤ a, b, c, d ≤ n), separated by spaces.

Output

For each query print the length of the largest common prefix on a separate line.

Examples

Input

6
bbbabb
2 1
3 2
4 3
5 2
6 5
6
2 5 3 1
1 5 2 3
5 6 5 6
6 3 4 1
6 2 3 4
2 2 4 5


Output

2
2
2
0
1
0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
char c[300009];
int pw[300009], ni_pw[300009], h1[300009], h2[300009], size[300009],
    dep[300009], fa[300009], dw[300009], tim, q[300009], n, Q, su[300009];
const int mo = 1000010029, p1 = 137, ni_p1 = 131388179;
vector<int> g[300009];
struct V {
  int x, len, s;
};
void prep(int x, int fa) {
  h1[x] = (1ll * h1[fa] * p1 + c[x]) % mo,
  h2[x] = (h2[fa] + 1ll * pw[dep[x]] * c[x]) % mo, size[x] = 1;
  for (int i : g[x])
    if (i != fa) dep[i] = dep[x] + 1, prep(i, x), size[x] += size[i];
}
void dfs(int x, int ff) {
  int maxx = -1;
  fa[x] = ff, dw[x] = ++tim, q[tim] = x;
  for (int i : g[x])
    if (i != ff && (maxx == -1 || size[i] > size[maxx])) maxx = i;
  if (maxx != -1) su[maxx] = su[x], dfs(maxx, x);
  for (int i : g[x])
    if (i != ff && i != maxx) su[i] = i, dfs(i, x);
}
void take(int x, int y, vector<V> &t, int &lca) {
  vector<V> tmp;
  while (1) {
    if (su[x] == su[y]) {
      if (dw[x] < dw[y])
        tmp.push_back(V{dw[x], dw[y] - dw[x] + 1, 1}), lca = x;
      else
        t.push_back(V{dw[x], dw[x] - dw[y] + 1, -1}), lca = y;
      break;
    }
    if (dw[x] > dw[y])
      t.push_back(V{dw[x], dw[x] - dw[su[x]] + 1, -1}), x = fa[su[x]];
    else
      tmp.push_back(V{dw[su[y]], dw[y] - dw[su[y]] + 1, 1}), y = fa[su[y]];
  }
  if (tmp.size())
    for (int i = tmp.size() - 1; i >= 0; --i) t.push_back(tmp[i]);
}
int gt(int x, int y, int lca) {
  if (lca == -1) lca = y;
  int d1 = dep[x] - dep[lca];
  return ((h1[x] - 1ll * h1[lca] * pw[d1] +
           1ll * (h2[y] - h2[fa[lca]]) * ni_pw[dep[lca]] % mo * pw[d1]) %
              mo +
          mo) %
         mo;
}
int main() {
  pw[0] = 1, ni_pw[0] = 1;
  scanf("%d", &n);
  scanf("%s", c + 1);
  for (int i = 1; i <= n; i++)
    pw[i] = 1ll * pw[i - 1] * p1 % mo,
    ni_pw[i] = 1ll * ni_pw[i - 1] * ni_p1 % mo;
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), g[x].push_back(y), g[y].push_back(x);
  prep(1, 0), su[1] = 1, dfs(1, 0);
  scanf("%d", &Q);
  while (Q--) {
    int u, v, x, y;
    scanf("%d%d%d%d", &x, &y, &u, &v);
    vector<V> t1, t2;
    int lca1, lca2;
    take(x, y, t1, lca1), take(u, v, t2, lca2);
    int len1 = t1.size(), len2 = t2.size(), p1 = 0, p2 = 0, l1 = 0, l2 = 0,
        ans = 0, d1, d2;
    while (p1 < len1 && p2 < len2) {
      int len = min(t1[p1].len - l1, t2[p2].len - l2);
      d1 = t1[p1].s, d2 = t2[p2].s;
      if (gt(x, q[t1[p1].x + (l1 + len - 1) * d1], d1 == -1 ? -1 : lca1) !=
          gt(u, q[t2[p2].x + (l2 + len - 1) * d2], d2 == -1 ? -1 : lca2))
        break;
      l1 += len, l2 += len;
      if (l1 >= t1[p1].len) p1++, l1 = 0;
      if (l2 >= t2[p2].len) p2++, l2 = 0;
      ans += len;
    }
    if (p1 >= len1 || p2 >= len2) {
      printf("%d\n", ans);
      continue;
    }
    int maxlen = min(t1[p1].len - l1, t2[p2].len - l2);
    for (int i = 20; i >= 0; --i)
      if (maxlen >= 1 << i)
        if (gt(x, q[t1[p1].x + (l1 + (1 << i) - 1) * d1],
               d1 == -1 ? -1 : lca1) ==
            gt(u, q[t2[p2].x + (l2 + (1 << i) - 1) * d2], d2 == -1 ? -1 : lca2))
          maxlen -= 1 << i, l1 += 1 << i, l2 += 1 << i, ans += 1 << i;
    printf("%d\n", ans);
  }
}