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 + 5, MOD = 1e9 + 7;
char s[N], buf[1 << 20];
int ppp, qqq;
inline char gc() {
  if (ppp == qqq) ppp = 0, qqq = fread(buf, 1, 1 << 20, stdin);
  return buf[ppp++];
}
inline void rs() {
  char x;
  int t = 0;
  while ((x = getchar()) < 'a' || x > 'z')
    ;
  s[++t] = x;
  while ((x = getchar()) >= 'a' && x <= 'z') s[++t] = x;
}
inline int rd() {
  char x;
  while ((x = getchar()) < '0' || x > '9')
    ;
  int t = x - '0';
  while ((x = getchar()) >= '0' && x <= '9') t = t * 10 + x - '0';
  return t;
}
int bg[N], nx[N * 2], to[N * 2], tl, hs1[N], hs2[N], p29[N], pinv[N], lg2[N];
inline void add(int x, int y) {
  nx[++tl] = bg[x];
  bg[x] = tl;
  to[tl] = y;
}
inline int qpow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = 1ll * ret * x % MOD;
    x = 1ll * x * x % MOD;
    y >>= 1;
  }
  return ret;
}
int dep[N], mxd[N], son[N], top[N], up[N], dw[N], fa[N][20], num[N], dfn;
void dfs1(int now, int f, int depth) {
  dep[now] = depth;
  fa[now][0] = f;
  mxd[now] = depth;
  for (int i = 1; i < 20; i++) {
    if (!fa[fa[now][i - 1]][i - 1]) break;
    fa[now][i] = fa[fa[now][i - 1]][i - 1];
  }
  hs1[now] = (hs1[f] + 1ll * (s[now] - 'a') * p29[depth - 1]) % MOD;
  hs2[now] = (29ll * hs2[f] + s[now] - 'a') % MOD;
  for (int i = bg[now]; i; i = nx[i]) {
    int aim = to[i];
    if (aim == f) continue;
    dfs1(aim, now, depth + 1);
    if (mxd[aim] > mxd[son[now]]) son[now] = aim;
    mxd[now] = max(mxd[now], mxd[aim]);
  }
}
void dfs2(int now, int tp) {
  top[now] = tp, num[now] = ++dfn;
  if (now == tp) {
    int len = mxd[now] - dep[now], tmp = now;
    for (int i = 0; i <= len; i++) dw[dfn + i] = tmp, tmp = son[tmp];
    tmp = now;
    for (int i = 0; i <= len; i++) up[dfn + i] = tmp, tmp = fa[tmp][0];
  }
  if (son[now]) dfs2(son[now], tp);
  for (int i = bg[now]; i; i = nx[i]) {
    int aim = to[i];
    if (aim == fa[now][0] || aim == son[now]) continue;
    dfs2(aim, aim);
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int i, dt = dep[x] - dep[y];
  for (i = 0; i < dt; i++) {
    if ((1 << i) > dt) break;
    if ((1 << i) & dt) x = fa[x][i];
  }
  if (x == y) return x;
  for (i = 19; i >= 0; i--) {
    if (fa[x][i] == fa[y][i]) continue;
    x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
inline int kth_anc(int x, int k) {
  if (k == 0) return x;
  x = fa[x][lg2[k]], k -= 1 << lg2[k];
  int tp = top[x], dt = dep[x] - dep[tp] - k;
  if (dt >= 0)
    return dw[num[tp] + dt];
  else
    return up[num[tp] - dt];
}
int main() {
  int n = rd(), q, i;
  rs();
  for (i = 1; i < n; i++) {
    int x = rd(), y = rd();
    add(x, y), add(y, x);
  }
  p29[0] = pinv[0] = 1, lg2[0] = -1;
  for (i = 1; i <= n; i++) {
    p29[i] = 1ll * p29[i - 1] * 29 % MOD, pinv[i] = qpow(p29[i], MOD - 2);
    lg2[i] = lg2[i >> 1] + 1;
  }
  dfs1(1, 0, 1);
  dfs2(1, 1);
  q = rd();
  for (i = 1; i <= q; i++) {
    int a = rd(), b = rd(), c = rd(), d = rd();
    int ac1 = lca(a, b), ac2 = lca(c, d);
    int len1 = dep[a] + dep[b] - dep[ac1] * 2 + 1,
        len2 = dep[c] + dep[d] - dep[ac2] * 2 + 1;
    int dis1 = dep[a] - dep[ac1] + 1, dis2 = dep[c] - dep[ac2] + 1;
    int l = 1, r = min(len1, len2), ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      int h1 = 0, h2 = 0;
      if (mid > dis1) {
        int rem = mid - dis1;
        int lf =
            1ll * (hs1[a] - hs1[fa[ac1][0]] + MOD) * pinv[dep[ac1] - 1] % MOD;
        int rp = kth_anc(b, dep[b] - dep[ac1] - rem);
        int rt = (0ll + hs2[rp] -
                  1ll * hs2[ac1] * p29[dep[rp] - dep[ac1]] % MOD + MOD) %
                 MOD;
        h1 = (1ll * lf * p29[rem] + rt) % MOD;
      } else {
        int lp = kth_anc(a, mid - 1);
        h1 = 1ll * (hs1[a] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD;
      }
      if (mid > dis2) {
        int rem = mid - dis2;
        int lf =
            1ll * (hs1[c] - hs1[fa[ac2][0]] + MOD) * pinv[dep[ac2] - 1] % MOD;
        int rp = kth_anc(d, dep[d] - dep[ac2] - rem);
        int rt = (0ll + hs2[rp] -
                  1ll * hs2[ac2] * p29[dep[rp] - dep[ac2]] % MOD + MOD) %
                 MOD;
        h2 = (1ll * lf * p29[rem] + rt) % MOD;
      } else {
        int lp = kth_anc(c, mid - 1);
        h2 = 1ll * (hs1[c] - hs1[fa[lp][0]] + MOD) * pinv[dep[lp] - 1] % MOD;
      }
      if (h1 == h2)
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}