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>
const int b1 = 17, b2 = 23, mod = 1e9 + 7, mod2 = 998244353;
int fa[300005], d[300005], anc[300005][21], pw1[300005], pw2[300005],
    ipw1[300005], ipw2[300005], up1[300005], up2[300005], down1[300005],
    down2[300005], son[300005], top[300005], h[300005], lg[300005], n, q;
char s[300005];
std::vector<int> ch[300005], up[300005], down[300005];
int qpow(int a, int b, int M) {
  if (b == 0) return 1;
  long long d = qpow(a, b >> 1, M);
  d = d * d % M;
  if (b & 1) d = d * a % M;
  return d;
}
int dec(int x, int M) { return x >= M ? x - M : x; }
void dfs(int u, int f) {
  fa[u] = f;
  d[u] = d[fa[u]] + 1;
  h[u] = 1;
  anc[u][0] = fa[u];
  down1[u] = ((long long)down1[fa[u]] * b1 % mod + s[u] - 'a') % mod;
  down2[u] = ((long long)down2[fa[u]] * b2 % mod2 + s[u] - 'a') % mod2;
  up1[u] = dec(up1[fa[u]] + (long long)(s[u] - 'a') * pw1[d[u]] % mod, mod);
  up2[u] = dec(up2[fa[u]] + (long long)(s[u] - 'a') * pw2[d[u]] % mod2, mod2);
  for (int i = 1; anc[u][i - 1] && i <= 20; ++i)
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
  for (int v : ch[u]) {
    if (v == f) continue;
    dfs(v, u);
    h[u] = std::max(h[v] + 1, h[u]);
    if (h[v] > h[son[u]]) son[u] = v;
  }
}
void dfs1(int u, int tp) {
  top[u] = tp;
  if (u == tp) {
    for (int i = 1, x = u; i <= h[u]; ++i) {
      up[u].push_back(x);
      x = fa[x];
    }
    for (int i = 1, x = u; i <= h[u]; ++i) {
      down[u].push_back(x);
      x = son[x];
    }
  }
  for (int v : ch[u])
    if (v != fa[u]) dfs1(v, son[u] == v ? tp : v);
}
int lca(int u, int v) {
  if (d[u] < d[v]) std::swap(u, v);
  for (int i = lg[d[u]]; i >= 0; i--)
    if (d[anc[u][i]] >= d[v]) u = anc[u][i];
  if (u == v) return u;
  for (int i = lg[d[u]]; i >= 0; i--)
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  return anc[u][0];
}
int lift(int x, int k) {
  if (!k) return x;
  int u = anc[x][lg[k]];
  k -= (1 << lg[k]) + d[u] - d[top[u]];
  return k >= 0 ? up[top[u]][k] : down[top[u]][-k];
}
std::pair<int, int> hash(int x, int l, int y, int len) {
  if (len <= d[x] - d[l] + 1) {
    int p = lift(x, len - 1);
    return std::make_pair(
        (long long)dec(up1[x] - up1[fa[p]] + mod, mod) * ipw1[d[p]] % mod,
        (long long)dec(up2[x] - up2[fa[p]] + mod2, mod2) * ipw2[d[p]] % mod2);
  } else {
    len -= (d[x] - d[l] + 1);
    int p = lift(y, d[y] - d[l] - len);
    return std::make_pair(
        dec((long long)dec(up1[x] - up1[fa[l]] + mod, mod) * ipw1[d[l]] % mod *
                    pw1[len] % mod +
                dec(down1[p] - ((long long)down1[l] * pw1[len] % mod) + mod,
                    mod),
            mod),
        dec((long long)dec(up2[x] - up2[fa[l]] + mod2, mod2) * ipw2[d[l]] %
                    mod2 * pw2[len] % mod2 +
                dec(down2[p] - ((long long)down2[l] * pw2[len] % mod2) + mod2,
                    mod2),
            mod2));
  }
}
int read() {
  char c = getchar();
  int x = 0;
  while (c < '0' || c > '9') c = getchar();
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
int main() {
  scanf("%d%s", &n, s + 1);
  lg[0] = -1;
  pw1[0] = pw2[0] = ipw1[0] = ipw2[0] = 1;
  int inv1 = qpow(b1, mod - 2, mod);
  int inv2 = qpow(b2, mod2 - 2, mod2);
  for (int i = 1; i <= n; ++i) {
    pw1[i] = (long long)pw1[i - 1] * b1 % mod;
    pw2[i] = (long long)pw2[i - 1] * b2 % mod2;
    ipw1[i] = (long long)ipw1[i - 1] * inv1 % mod;
    ipw2[i] = (long long)ipw2[i - 1] * inv2 % mod2;
    lg[i] = lg[i / 2] + 1;
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    u = read();
    v = read();
    ch[u].push_back(v);
    ch[v].push_back(u);
  }
  dfs(1, 0);
  dfs1(1, 1);
  scanf("%d", &q);
  while (q--) {
    int a1, b1, a2, b2;
    a1 = read();
    b1 = read();
    a2 = read();
    b2 = read();
    int l1 = lca(a1, b1), l2 = lca(a2, b2);
    int d1 = d[a1] + d[b1] - 2 * d[l1] + 1;
    int d2 = d[a2] + d[b2] - 2 * d[l2] + 1;
    int l = 1, r = std::min(d1, d2), ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (hash(a1, l1, b1, mid) == hash(a2, l2, b2, mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}