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;
namespace SA {
const int Max_N(600050);
int N, SA[Max_N], wa[Max_N], wb[Max_N], Cnt[Max_N], Rank[Max_N], Height[Max_N],
    Log[Max_N], ST[20][Max_N];
char S[Max_N];
void getSA() {
  int M = 128, *x = wa, *y = wb;
  for (int i = 1; i <= N; ++i) ++Cnt[x[i] = S[i]];
  for (int i = 1; i <= M; ++i) Cnt[i] += Cnt[i - 1];
  for (int i = N; i >= 1; --i) SA[Cnt[x[i]]--] = i;
  for (int k = 1, p; k <= N; k <<= 1) {
    p = 0;
    for (int i = N - k + 1; i <= N; ++i) y[++p] = i;
    for (int i = 1; i <= N; ++i)
      if (SA[i] > k) y[++p] = SA[i] - k;
    memset(Cnt, 0, sizeof(Cnt));
    for (int i = 1; i <= N; ++i) ++Cnt[x[i]];
    for (int i = 1; i <= M; ++i) Cnt[i] += Cnt[i - 1];
    for (int i = N; i >= 1; --i) SA[Cnt[x[y[i]]]--] = y[i];
    swap(x, y), x[SA[1]] = p = 1;
    for (int i = 2; i <= N; ++i) {
      if (y[SA[i - 1]] != y[SA[i]] || y[SA[i - 1] + k] != y[SA[i] + k]) ++p;
      x[SA[i]] = p;
    }
    if ((M = p) == N) break;
  }
  for (int i = 1; i <= N; ++i) Rank[SA[i]] = i;
  for (int i = 1, j, k = 0; i <= N; ++i) {
    if (k) --k;
    j = SA[Rank[i] - 1];
    while (S[i + k] == S[j + k]) ++k;
    Height[Rank[i]] = k;
  }
  Log[0] = Log[1] = 0;
  for (int i = 2; i <= N; ++i) Log[i] = Log[i >> 1] + 1;
  for (int i = 1; i <= N; ++i) ST[0][i] = Height[i];
  for (int j = 1; (1 << j) <= N; ++j)
    for (int i = 1; i + (1 << j) - 1 <= N; ++i)
      ST[j][i] = min(ST[j - 1][i], ST[j - 1][i + (1 << (j - 1))]);
}
inline int rmq(int l, int r) {
  int k = Log[r - l + 1];
  return min(ST[k][l], ST[k][r - (1 << k) + 1]);
}
inline int lcp(int l1, int r1, int l2, int r2) {
  return l1 == l2
             ? min(r1 - l1 + 1, r2 - l2 + 1)
             : min(rmq(min(Rank[l1], Rank[l2]) + 1, max(Rank[l1], Rank[l2])),
                   min(r1 - l1 + 1, r2 - l2 + 1));
}
}  // namespace SA
const int Max_N(300050);
int N, Head[Max_N], Total, To[Max_N << 1], Next[Max_N << 1], Father[Max_N],
    Deep[Max_N], Size[Max_N], Son[Max_N], Top[Max_N], dfsclock, Pre[Max_N],
    ID[Max_N];
char V[Max_N];
inline void Add_Edge(int s, int t) {
  ++Total, To[Total] = t, Next[Total] = Head[s], Head[s] = Total;
}
void dfs1(int u) {
  Size[u] = 1;
  for (int i = Head[u], v; i; i = Next[i])
    if ((v = To[i]) != Father[u]) {
      Father[v] = u, Deep[v] = Deep[u] + 1, dfs1(v), Size[u] += Size[v];
      if (Size[v] > Size[Son[u]]) Son[u] = v;
    }
}
void dfs2(int u) {
  ID[Pre[u] = ++dfsclock] = u;
  int v;
  if (v = Son[u]) Top[v] = Top[u], dfs2(v);
  for (int i = Head[u]; i; i = Next[i])
    if ((v = To[i]) != Father[u] && v != Son[u]) Top[v] = v, dfs2(v);
}
int LCA(int u, int v) {
  int r1(Top[u]), r2(Top[v]);
  while (r1 != r2) {
    if (Deep[r1] < Deep[r2]) swap(r1, r2), swap(u, v);
    u = Father[r1], r1 = Top[u];
  }
  if (Deep[u] > Deep[v]) swap(u, v);
  return u;
}
struct seg {
  int l, r;
  void give(int _l, int _r) { l = _l, r = _r; }
  void give(int _l, int _r, bool rev) {
    if (rev)
      give(N + (N - _r + 1), N + (N - _l + 1));
    else
      give(_l, _r);
  }
};
int CX, CY;
seg X[Max_N], Y[Max_N];
void get(int &n, seg *V, int s, int t) {
  n = 0;
  int lca = LCA(s, t);
  for (int r = Top[s]; r != Top[lca]; s = Father[r], r = Top[s])
    V[++n].give(Pre[r], Pre[s], true);
  V[++n].give(Pre[lca], Pre[s], true);
  int _n = n;
  for (int r = Top[t]; r != Top[lca]; t = Father[r], r = Top[t])
    V[++n].give(Pre[r], Pre[t], false);
  if (Pre[lca] + 1 <= Pre[t]) V[++n].give(Pre[lca] + 1, Pre[t], false);
  reverse(V + _n + 1, V + n + 1);
}
int main() {
  scanf("%d", &N);
  scanf("%s", V + 1);
  for (int i = 1, u, v; i != N; ++i)
    scanf("%d%d", &u, &v), Add_Edge(u, v), Add_Edge(v, u);
  dfs1(1), Top[1] = 1, dfs2(1);
  for (int i = 1; i <= N; ++i) SA::S[++SA::N] = V[ID[i]];
  for (int i = N; i >= 1; --i) SA::S[++SA::N] = V[ID[i]];
  SA::getSA();
  int M;
  scanf("%d", &M);
  for (int a, b, c, d, Ans; M--;) {
    scanf("%d%d%d%d", &a, &b, &c, &d), get(CX, X, a, b), get(CY, Y, c, d),
        Ans = 0;
    for (int i = 1, j = 1, p = 0, q = 0, lcp, flag; i <= CX && j <= CY;) {
      flag = 0;
      lcp = SA::lcp(X[i].l + p, X[i].r, Y[j].l + q, Y[j].r);
      Ans += lcp, p += lcp, q += lcp;
      if (X[i].l + p > X[i].r) ++i, p = 0, flag = 1;
      if (Y[j].l + q > Y[j].r) ++j, q = 0, flag = 1;
      if (flag == 0) break;
    }
    printf("%d\n", Ans);
  }
  return 0;
}