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;
template <typename T>
inline void Read(T &n) {
  char ch;
  bool flag = false;
  while (!isdigit(ch = getchar()))
    if (ch == '-') flag = true;
  for (n = ch ^ 48; isdigit(ch = getchar());
       n = (n << 1) + (n << 3) + (ch ^ 48))
    ;
  if (flag) n = -n;
}
const int MAXN = 300005;
const int MOD = 998244353;
const int base = 1107;
inline int ksm(int base, int k = MOD - 2) {
  int res = 1;
  while (k) {
    if (k & 1) res = 1ll * res * base % MOD;
    base = 1ll * base * base % MOD;
    k >>= 1;
  }
  return res;
}
int n, Q;
struct _ {
  int nxt, to;
  _(int nxt = 0, int to = 0) : nxt(nxt), to(to) {}
} edge[MAXN << 1];
int fst[MAXN], tot;
inline void Add_Edge(int f, int t) {
  edge[++tot] = _(fst[f], t);
  fst[f] = tot;
  edge[++tot] = _(fst[t], f);
  fst[t] = tot;
}
int Pow[MAXN << 1], invPow[MAXN << 1];
char a[MAXN];
int fa[MAXN][19], dep[MAXN], hs1[MAXN], hs2[MAXN], son[MAXN], mxdep[MAXN];
void dfs1(int x, int y) {
  fa[x][0] = y;
  for (register int i = 1; i < 19; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  mxdep[x] = dep[x] = dep[y] + 1;
  hs1[x] = (1ll * base * hs1[y] % MOD + a[x] - 'a') % MOD;
  hs2[x] = (hs2[y] + 1ll * Pow[dep[x]] * (a[x] - 'a') % MOD) % MOD;
  for (register int u = fst[x]; u; u = edge[u].nxt) {
    int v = edge[u].to;
    if (v == y) continue;
    dfs1(v, x);
    mxdep[x] = max(mxdep[v], mxdep[x]);
    if (mxdep[v] > mxdep[son[x]]) son[x] = v;
  }
}
vector<int> up[MAXN], down[MAXN];
int top[MAXN];
void dfs2(int x, int y) {
  top[x] = y;
  down[y].push_back(x);
  if (son[x]) dfs2(son[x], y);
  for (register int u = fst[x]; u; u = edge[u].nxt) {
    int v = edge[u].to;
    if (v == son[x] or v == fa[x][0]) continue;
    dfs2(v, v);
  }
}
int Log[MAXN];
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (register int i = 18; i >= 0; i--)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (register int i = 18; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline int kfa(int u, int k) {
  if (k == 0) return u;
  u = fa[u][Log[k]];
  k -= (1 << Log[k]);
  int dlt = dep[u] - dep[top[u]];
  if (dlt >= k) return down[top[u]][dlt - k];
  return up[top[u]][k - dlt];
}
inline int get(int Up, int Down, int opt) {
  if (opt == 1)
    return Up == 1
               ? hs1[Down]
               : (hs1[Down] -
                  1ll * Pow[dep[Down] - dep[fa[Up][0]]] * hs1[fa[Up][0]] % MOD +
                  MOD) %
                     MOD;
  if (opt == 2)
    return Up == 1 ? hs2[Down]
                   : 1ll * (hs2[Down] - hs2[fa[Up][0]] + MOD) % MOD *
                         invPow[dep[Up]] % MOD;
}
inline int check(int u, int v, int Lca, int dis) {
  if (dep[u] - dis + 1 >= dep[Lca]) return get(kfa(u, dis - 1), u, 1);
  dis = dep[u] + dep[v] - 2 * dep[Lca] + 1 - dis + 1;
  int L = get(Lca, u, 1), R = get(Lca, kfa(v, dis - 1), 2);
  return ((L + 1ll * R * Pow[dep[u] - dep[Lca]] % MOD) % MOD -
          1ll * Pow[dep[u] - dep[Lca]] * (a[Lca] - 'a') % MOD + MOD) %
         MOD;
}
int main() {
  Read(n);
  scanf("%s", a + 1);
  for (register int i = 1; i < n; i++) {
    int f, t;
    Read(f);
    Read(t);
    Add_Edge(f, t);
  }
  Pow[0] = 1;
  for (register int i = 1; i <= n; i++) Pow[i] = 1ll * base * Pow[i - 1] % MOD;
  invPow[0] = 1;
  invPow[1] = ksm(base);
  for (register int i = 2; i <= n; i++)
    invPow[i] = 1ll * invPow[i - 1] * invPow[1] % MOD;
  dep[1] = -1;
  dfs1(1, 1);
  dfs2(1, 1);
  for (register int i = 1; i <= n; i++)
    if (top[i] == i)
      for (register int j = 0, tmp = i; j <= mxdep[i] - dep[i] + 1;
           j++, tmp = fa[tmp][0])
        up[i].push_back(tmp);
  Log[1] = 0;
  for (register int i = 2; i <= n; i++) Log[i] = Log[i >> 1] + 1;
  Read(Q);
  while (Q--) {
    int u, v, uu, vv;
    Read(u);
    Read(v);
    Read(uu);
    Read(vv);
    int lca1 = lca(u, v), lca2 = lca(uu, vv);
    int dis1 = dep[u] + dep[v] - 2 * dep[lca1] + 1;
    int dis2 = dep[uu] + dep[vv] - 2 * dep[lca2] + 1;
    int head = 1, tail = min(dis1, dis2) + 1, mid;
    while (head < tail) {
      mid = head + tail >> 1;
      if (check(u, v, lca1, mid) == check(uu, vv, lca2, mid))
        head = mid + 1;
      else
        tail = mid;
    }
    printf("%d\n", head - 1);
  }
  return 0;
}