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;
int n, m;
int head[300005], nex[300005 << 1], to[300005 << 1], cntE;
int fa[300005][22], len[300005], son[300005], top[300005];
int dep[300005], hib[300005];
char c[300005];
const int mod = 1e9 + 7, bs = 127;
int h1[300005], h2[300005], pw[300005], ipw[300005];
vector<int> up[300005], dw[300005];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
inline int fpm(int x, int y) {
  int re = 1;
  while (y) {
    if (y & 1) re = 1LL * re * x % mod;
    x = 1LL * x * x % mod, y >>= 1;
  }
  return re;
}
inline void addE(int u, int v) {
  to[++cntE] = v;
  nex[cntE] = head[u], head[u] = cntE;
}
void dfs_1(int u) {
  dep[u] = dep[fa[u][0]] + 1;
  for (int i = 0; i < 20; ++i) {
    if (!fa[u][i]) continue;
    fa[u][i + 1] = fa[fa[u][i]][i];
  }
  for (int i = head[u], v; i; i = nex[i]) {
    v = to[i];
    if (v == fa[u][0]) continue;
    fa[v][0] = u, dfs_1(v);
    if (len[v] > len[son[u]]) son[u] = v;
  }
  len[u] = len[son[u]] + 1;
}
void dfs_2(int u, int _top) {
  top[u] = _top;
  if (son[u]) dfs_2(son[u], _top);
  for (int i = head[u], v; i; i = nex[i]) {
    v = to[i];
    if (v == son[u] || v == fa[u][0]) continue;
    dfs_2(v, v);
  }
}
void getHash(int u) {
  h1[u] = (1LL * bs * h1[fa[u][0]] + int(c[u])) % mod;
  h2[u] = (h2[fa[u][0]] + 1LL * pw[dep[u] - 1] * int(c[u])) % mod;
  for (int i = head[u], v; i; i = nex[i]) {
    v = to[i];
    if (v == fa[u][0]) continue;
    getHash(v);
  }
}
void prepare() {
  dfs_1(1);
  dfs_2(1, 1);
  for (int i = 1; i <= n; ++i) {
    if (top[i] != i) continue;
    dw[i].resize(len[i]);
    for (int j = 0, u = i; j < len[i]; ++j, u = son[u]) dw[i][j] = u;
    int sz = min(len[i], dep[i]);
    up[i].resize(sz);
    for (int j = 0, u = i; j < sz; ++j, u = fa[u][0]) up[i][j] = u;
  }
  for (int i = 2; i <= n; ++i) hib[i] = hib[i >> 1] + 1;
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = 1LL * bs * pw[i - 1] % mod;
  ipw[n] = fpm(pw[n], mod - 2);
  for (int i = n; i; --i) ipw[i - 1] = 1LL * bs * ipw[i] % mod;
  getHash(1);
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; ~i; --i)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = 20; ~i; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline int getFa(int u, int k) {
  if (k == 0) return u;
  u = fa[u][hib[k]], k -= (1 << hib[k]) + dep[u] - dep[top[u]];
  return k > 0 ? up[top[u]][k] : dw[top[u]][-k];
}
inline int get(int s, int t, int l, int n) {
  int re;
  if (n >= dep[s] - dep[l] + 1) {
    int d = dep[s] - dep[l] + 1;
    re = (h1[s] - 1LL * pw[d] * h1[fa[l][0]] % mod + mod) % mod;
    n -= d;
    int k = dep[t] - dep[l] - n;
    d -= dep[l];
    re = (re +
          1LL * (h2[getFa(t, k)] - h2[l] + mod) * (d > 0 ? pw[d] : ipw[-d])) %
         mod;
  } else {
    re = (h1[s] - 1LL * pw[n] * h1[getFa(s, n)] % mod + mod) % mod;
  }
  return re;
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    char ch = getchar();
    while (ch == '\n' || ch == ' ') ch = getchar();
    c[i] = ch;
  }
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d %d", &u, &v);
    addE(u, v), addE(v, u);
  }
  prepare();
  m = read();
  for (int i = 1, a, b, c, d, a1, a2; i <= m; ++i) {
    a = read(), b = read(), c = read(), d = read();
    a1 = lca(a, b), a2 = lca(c, d);
    int l = 0, r = 1 + min(dep[a] + dep[b] - 2 * dep[a1],
                           dep[c] + dep[d] - 2 * dep[a2]);
    int mid, mpos = 0;
    while (l <= r) {
      mid = l + r >> 1;
      if (get(a, b, a1, mid) == get(c, d, a2, mid)) {
        if (mid > mpos) mpos = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    printf("%d\n", mpos);
  }
  return 0;
}