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 = 1e6 + 500;
const int mod = 1021417363;
int Base, pw[N], ipw[N], dep[N], pool[N], *poolp = pool, *upstk[N], *downstk[N],
                                          fst[N], nxt[N], to[N], mm, n;
int hsh[N], rhsh[N], fa[305000][19], highbit[N];
int tp[N], size[N], son[N], mxlen[N], son_len[N], tp_len[N];
char st[N];
int qmod(int x) { return x + (x >> 31 & mod); }
int qpower(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
void hash_prework() {
  Base = rand();
  pw[0] = 1;
  for (int i = 1; i <= n; i++) pw[i] = 1ll * pw[i - 1] * Base % mod;
  int iBase = qpower(Base, mod - 2);
  ipw[0] = 1;
  for (int i = 1; i <= n; i++) ipw[i] = 1ll * ipw[i - 1] * iBase % mod;
  highbit[1] = 0;
  for (int i = 2; i <= n; i++) highbit[i] = highbit[i >> 1] + 1;
}
int lca(int u, int v) {
  for (; tp[u] != tp[v];
       dep[tp[u]] < dep[tp[v]] ? v = fa[tp[v]][0] : u = fa[tp[u]][0])
    ;
  return dep[u] < dep[v] ? u : v;
}
void dfs(int u, int Fa) {
  dep[u] = dep[Fa] + 1;
  fa[u][0] = Fa;
  for (int i = 1; i <= 18; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  hsh[u] = (1ll * hsh[Fa] * Base + st[u]) % mod,
  rhsh[u] = (rhsh[Fa] + 1ll * st[u] * pw[dep[u]]) % mod;
  size[u] = 1;
  int mx = 0;
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == Fa) continue;
    dfs(v, u);
    size[u] += size[v];
    if (size[v] > mx) mx = size[v], son[u] = v;
    if (mxlen[v] > mxlen[u]) son_len[u] = v, mxlen[u] = mxlen[v];
  }
  ++mxlen[u];
}
void dfs2(int u, int top) {
  tp[u] = top;
  if (son[u]) dfs2(son[u], top);
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa[u][0] || v == son[u]) continue;
    dfs2(v, v);
  }
}
void dfs3(int u, int top) {
  tp_len[u] = top;
  if (u == top) {
    upstk[u] = poolp;
    poolp += mxlen[u];
    downstk[u] = poolp;
    poolp += mxlen[u];
    int tu = u;
    for (int i = 0; i < mxlen[u]; i++) upstk[u][i] = tu, tu = fa[tu][0];
  } else
    downstk[u] = downstk[fa[u][0]] + 1;
  downstk[u][0] = u;
  if (son_len[u]) dfs3(son_len[u], top);
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa[u][0] || v == son_len[u]) continue;
    dfs3(v, v);
  }
}
int kthfa(int u, int K) {
  if (!K) return u;
  int tu = fa[u][highbit[K]], tpu = tp_len[tu];
  K -= 1 << highbit[K];
  return dep[tu] - dep[tpu] >= K ? downstk[tpu][dep[tu] - dep[tpu] - K]
                                 : upstk[tpu][K - dep[tu] + dep[tpu]];
}
int gethsh(int u, int v, int l, int len) {
  if (len <= dep[u] - dep[l] + 1) {
    int anc = kthfa(u, len - 1);
    return qmod(1ll * (rhsh[u] - rhsh[fa[anc][0]]) * ipw[dep[anc]] % mod);
  }
  int anc = kthfa(v, dep[u] + dep[v] - 2 * dep[l] - (len - 1));
  return qmod((1ll * (rhsh[u] - rhsh[fa[l][0]]) * ipw[dep[l]] % mod *
                   pw[dep[anc] - dep[l]] +
               hsh[anc] - 1ll * hsh[l] * pw[dep[anc] - dep[l]]) %
              mod);
}
void ade(int u, int v) { to[++mm] = v, nxt[mm] = fst[u], fst[u] = mm; }
int main() {
  scanf("%d", &n);
  hash_prework();
  scanf("%s", st + 1);
  for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), ade(u, v), ade(v, u);
  dep[0] = -1;
  dfs(1, 0);
  dfs2(1, 1);
  dfs3(1, 1);
  int qn;
  scanf("%d", &qn);
  for (int i = 1, u1, v1, u2, v2; i <= qn; i++) {
    scanf("%d%d%d%d", &u1, &v1, &u2, &v2);
    int l1 = lca(u1, v1), l2 = lca(u2, v2),
        len1 = dep[u1] + dep[v1] - 2 * dep[l1],
        len2 = dep[u2] + dep[v2] - 2 * dep[l2];
    int l = 0, r = min(len1, len2) + 1, mid;
    while (l < r) {
      mid = (l + r + 1) >> 1;
      if (gethsh(u1, v1, l1, mid) == gethsh(u2, v2, l2, mid))
        l = mid;
      else
        r = mid - 1;
    }
    printf("%d\n", l);
  }
}