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;
const int N = 3e5 + 10, MOD = 1e9 + 7;
int n, m, sum[N][2], de[N], mi[N], inv[N], v[N], fa[N], siz[N], son[N], top[N];
int head[N], nxt[N << 1], to[N << 1], cnt;
char s[N];
vector<int> p[N];
inline void add(int x, int y) {
  ++cnt;
  nxt[cnt] = head[x];
  head[x] = cnt;
  to[cnt] = y;
  return;
}
inline int ksm(int x, int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = 1ll * res * x % MOD;
    y >>= 1;
    x = 1ll * x * x % MOD;
  }
  return res;
}
void dfs(int x, int f) {
  fa[x] = f;
  de[x] = de[f] + 1;
  sum[x][0] = (29ll * sum[f][0] + v[x]) % MOD;
  sum[x][1] = (0ll + sum[f][1] + 1ll * v[x] * mi[de[f]] % MOD) % MOD;
  siz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y != f) {
      dfs(y, x);
      siz[x] += siz[y];
      if (siz[son[x]] < siz[y]) son[x] = y;
    }
  }
  return;
}
void dfs2(int x, int tpp) {
  top[x] = tpp;
  p[tpp].push_back(x);
  if (!son[x]) return;
  dfs2(son[x], tpp);
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y != son[x] && y != fa[x]) dfs2(y, y);
  }
  return;
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (de[top[x]] < de[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return de[x] < de[y] ? x : y;
}
int get_k(int x, int k) {
  while ((de[x] - de[top[x]]) < k) {
    k -= (de[x] - de[top[x]] + 1);
    x = fa[top[x]];
  }
  return p[top[x]][de[x] - de[top[x]] - k];
}
int solve(int a, int b, int c, int d) {
  int lca1 = LCA(a, b);
  int dis1 = de[a] + de[b] - 2 * de[lca1] + 1;
  int lca2 = LCA(c, d);
  int dis2 = de[c] + de[d] - 2 * de[lca2] + 1;
  int l = 1, r = min(dis1, dis2), res = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    int op1 = 0, op2 = 0;
    if ((de[a] - de[lca1] + 1) < mid) {
      op1 = 1ll * (sum[a][1] - sum[fa[lca1]][1] + MOD) % MOD *
            inv[de[fa[lca1]]] % MOD;
      int k = mid - (de[a] - de[lca1] + 1);
      int p1 = get_k(b, (de[b] - de[lca1] + 1) - (k + 1));
      int op3 =
          (1ll * sum[p1][0] - 1ll * sum[lca1][0] * mi[k] % MOD + MOD) % MOD;
      op1 = (1ll * op1 * mi[k] + op3) % MOD;
    } else {
      int p1 = get_k(a, mid - 1);
      op1 = (1ll * (sum[a][1] - sum[fa[p1]][1] + MOD) % MOD * inv[de[fa[p1]]]) %
            MOD;
    }
    if ((de[c] - de[lca2] + 1) < mid) {
      op2 = 1ll * (sum[c][1] - sum[fa[lca2]][1] + MOD) % MOD *
            inv[de[fa[lca2]]] % MOD;
      int k = mid - (de[c] - de[lca2] + 1);
      int p1 = get_k(d, (de[d] - de[lca2] + 1) - (k + 1));
      int op3 =
          (1ll * sum[p1][0] - 1ll * sum[lca2][0] * mi[k] % MOD + MOD) % MOD;
      op2 = (1ll * op2 * mi[k] + op3) % MOD;
    } else {
      int p1 = get_k(c, mid - 1);
      op2 = (1ll * (sum[c][1] - sum[fa[p1]][1] + MOD) % MOD * inv[de[fa[p1]]]) %
            MOD;
    }
    if (op1 == op2)
      res = max(res, mid), l = mid + 1;
    else
      r = mid - 1;
  }
  return res;
}
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = 1; i <= n; i++) v[i] = s[i] - 'a';
  mi[0] = 1;
  for (int i = 1; i <= n; i++) mi[i] = 29ll * mi[i - 1] % MOD;
  inv[n] = ksm(mi[n], MOD - 2);
  for (int i = n; i >= 1; i--) inv[i - 1] = 29ll * inv[i] % MOD;
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  dfs2(1, 1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", solve(a, b, c, d));
  }
  return 0;
}