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>
void read(T &t) {
  t = 0;
  char ch = getchar();
  int f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  do {
    (t *= 10) += ch - '0';
    ch = getchar();
  } while ('0' <= ch && ch <= '9');
  t *= f;
}
const int maxn = (6e5) + 10;
int n, q, tot, N, ans, nxt[maxn], head[maxn / 2], to[maxn];
int top[maxn / 2], sz[maxn / 2], son[maxn / 2];
int dep[maxn / 2], fa[maxn / 2], lg[maxn], dfn[maxn / 2];
char S[maxn], s[maxn];
void add(int x, int y) {
  tot++;
  nxt[tot] = head[x];
  head[x] = tot;
  to[tot] = y;
}
struct string {
  int sa[maxn], rk[maxn];
  int SA[maxn], RK[maxn];
  int h[maxn], st[maxn][21];
  int cnt[maxn];
  void initSA() {
    for (int i = 1; i <= N; i++) cnt[S[i]]++;
    for (int i = 'a'; i <= 'z' + 1; i++) cnt[i] += cnt[i - 1];
    for (int i = 1; i <= N; i++) sa[cnt[S[i]]--] = i;
    for (int i = 1; i <= N; i++)
      rk[sa[i]] = rk[sa[i - 1]] + (S[sa[i]] != S[sa[i - 1]]);
    for (int j = 1; j <= N; j *= 2) {
      for (int i = 1; i <= N; i++) cnt[rk[sa[i]]] = i;
      for (int i = N; i >= 1; i--)
        if (sa[i] > j) SA[cnt[rk[sa[i] - j]]--] = sa[i] - j;
      for (int i = N; i >= 1; i--)
        if (sa[i] > N - j) SA[cnt[rk[sa[i]]]--] = sa[i];
      for (int i = 1; i <= N; i++)
        RK[SA[i]] = RK[SA[i - 1]] + (rk[SA[i]] != rk[SA[i - 1]] ||
                                     rk[SA[i] + j] != rk[SA[i - 1] + j]);
      for (int i = 1; i <= N; i++) swap(sa[i], SA[i]), swap(rk[i], RK[i]);
      if (rk[sa[N]] >= N) break;
    }
  }
  int MN(int x, int y) {
    if (h[x] < h[y]) return x;
    return y;
  }
  void initH() {
    for (int i = 1, j, lst = 1; i <= N; i++) {
      j = sa[rk[i] - 1];
      if (lst) lst--;
      while (S[i + lst] == S[j + lst]) lst++;
      h[rk[i]] = lst;
    }
    for (int i = 1; i <= N; i++) st[i][0] = h[i];
    for (int j = 1; (1 << j) <= N; j++)
      for (int i = (1 << j); i <= N; i++)
        st[i][j] = min(st[i][j - 1], st[i - (1 << (j - 1))][j - 1]);
  }
  int STQ(int l, int r) {
    if (l == r) return N;
    l = rk[l];
    r = rk[r];
    if (l > r) swap(l, r);
    int j = lg[r - l];
    return min(st[r][j], st[l + (1 << j)][j]);
  }
} T;
void dfs(int u, int p) {
  sz[u] = 1;
  fa[u] = p;
  dep[u] = dep[p] + 1;
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v == p) continue;
    dfs(v, u);
    sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int t) {
  dfn[u] = ++N;
  S[N] = s[u];
  top[u] = t;
  if (son[u]) dfs2(son[u], t);
  for (int i = head[u], v; i; i = nxt[i]) {
    v = to[i];
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
int lca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  if (dep[x] < dep[y]) return x;
  return y;
}
vector<pair<int, int> > get() {
  vector<pair<int, int> > A, B;
  A.clear();
  B.clear();
  int x, y, z;
  read(x);
  read(y);
  z = lca(x, y);
  while (top[x] != top[z])
    A.push_back(make_pair(N - dfn[x] + 1, dfn[x] - dfn[top[x]] + 1)),
        x = fa[top[x]];
  A.push_back(make_pair(N - dfn[x] + 1, dfn[x] - dfn[z] + 1));
  while (top[y] != top[z])
    B.push_back(make_pair(dfn[top[y]], dfn[y] - dfn[top[y]] + 1)),
        y = fa[top[y]];
  if (y + z) B.push_back(make_pair(dfn[z] + 1, dfn[y] - dfn[z]));
  for (int i = B.size() - 1; i >= 0; i--) A.push_back(B[i]);
  return A;
}
vector<pair<int, int> > A, B;
int main() {
  read(n);
  scanf("%s", s + 1);
  int x, y, tmp;
  for (int i = 1; i < n; i++) {
    read(x);
    read(y);
    add(x, y);
    add(y, x);
  }
  tot = 0;
  dfs(1, 0);
  dfs2(1, 1);
  S[n + 1] = 'z' + 1;
  N = n * 2 + 1;
  for (int i = n + 2; i <= N; i++) S[i] = S[N - i + 1];
  for (int i = 2; i <= N; i++) lg[i] = lg[i / 2] + 1;
  T.initSA();
  T.initH();
  read(q);
  while (q--) {
    A = get();
    B = get();
    x = 0, y = 0, ans = 0;
    while (x < A.size() && y < B.size()) {
      tmp = T.STQ(A[x].first, B[y].first);
      tmp = min(tmp, A[x].second);
      tmp = min(tmp, B[y].second);
      ans += tmp;
      A[x].first += tmp;
      A[x].second -= tmp;
      B[y].first += tmp;
      B[y].second -= tmp;
      if (A[x].second && B[y].second) break;
      if (!A[x].second) x++;
      if (!B[y].second) y++;
    }
    printf("%d\n", ans);
  }
  return 0;
}