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 = 3e5 + 5, bs = 727, mod = 987654321 - 2;
int zrb(int a, int b) { return (1LL * a * b % mod); }
int jm(int a, int b) {
  int tmp = (a + b) % mod;
  if (tmp < 0) tmp += mod;
  return (tmp);
}
int pw(int a, int b) {
  int rt = 1;
  for (; b; b >>= 1) {
    if (b & 1) rt = zrb(rt, a);
    a = zrb(a, a);
  }
  return (rt);
}
int PS[N << 1], TV[N], INV[N], H[N], ID[N], P[N], HD[N], C[N], SZ[N], POS[N],
    POS2[N], NXT[N], n, nn, q, st, idcnt;
vector<int> adj[N];
char second[N];
void prDFS(int u, int p) {
  SZ[u] = 1;
  P[u] = p;
  for (int &x : adj[u])
    if (x ^ p) {
      H[x] = H[u] + 1;
      prDFS(x, u);
      SZ[u] += SZ[x];
    }
}
void DFS(int u, int p, int id) {
  PS[st++] = u;
  ID[u] = id;
  if (!HD[id]) HD[id] = u;
  int arshad = 0;
  for (int &x : adj[u])
    if (x ^ p && SZ[x] >= SZ[arshad]) arshad = x;
  if (arshad) {
    NXT[u] = arshad;
    DFS(arshad, u, id);
  }
  for (int &x : adj[u])
    if (x ^ p && x ^ arshad) DFS(x, u, ++idcnt);
}
int get(int l, int r) {
  int rt = PS[r];
  if (r < n && l) rt = jm(rt, -PS[l - 1]);
  if (r >= n && l ^ n) rt = jm(rt, -PS[l - 1]);
  if (l < n)
    rt = zrb(rt, INV[l]);
  else
    rt = zrb(rt, INV[l - n]);
  return (rt);
}
int LCA(int a, int b) {
  while (ID[a] ^ ID[b]) {
    if (H[HD[ID[a]]] > H[HD[ID[b]]])
      a = P[HD[ID[a]]];
    else
      b = P[HD[ID[b]]];
  }
  return (H[a] < H[b] ? a : b);
}
int getbs(int l1, int r1, int l2, int r2) {
  int ln = min(r1 - l1, r2 - l2);
  r1 = l1 + ln;
  r2 = l2 + ln;
  int l, r, mid;
  l = 0, r = ln + 1;
  while (r - l > 2) {
    mid = ((l + r) >> 1);
    if (get(l1, l1 + mid) == get(l2, l2 + mid))
      l = mid;
    else
      r = mid;
  }
  if (!l && get(l1, l1) ^ get(l2, l2)) return (0);
  for (int i = min(ln, l + 1); i >= max(0, l - 1); i--)
    if (get(l1, l1 + i) == get(l2, l2 + i)) return (i + 1);
  return (0);
}
int main() {
  scanf("%d", &n);
  scanf("%s", second);
  nn = n << 1;
  for (int i = 1; i <= n; i++) C[i] = second[i - 1] - 'a';
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  INV[0] = TV[0] = 1;
  for (int i = 1; i < N; i++) TV[i] = zrb(TV[i - 1], bs);
  INV[1] = pw(bs, mod - 2);
  for (int i = 2; i < N; i++) INV[i] = zrb(INV[i - 1], INV[1]);
  prDFS(1, 0);
  DFS(1, 0, 0);
  for (int i = n; i < nn; i++) PS[i] = PS[i - n];
  reverse(PS + n, PS + nn);
  for (int i = 0; i < n; i++) POS[PS[i]] = i;
  for (int i = n; i < nn; i++) POS2[PS[i]] = i;
  PS[0] = C[PS[0]];
  for (int i = 1; i < n; i++) PS[i] = jm(PS[i - 1], zrb(TV[i], C[PS[i]]));
  PS[n] = C[PS[n]];
  for (int i = n + 1; i < nn; i++)
    PS[i] = jm(PS[i - 1], zrb(TV[i - n], C[PS[i]]));
  scanf("%d", &q);
  for (int Q = 0; Q < q; Q++) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int lcab = LCA(a, b), lccd = LCA(c, d);
    vector<pair<int, int> > ab, ab2, cd, cd2;
    while (1) {
      if (ID[a] == ID[lcab]) {
        ab.push_back({POS2[a], POS2[lcab]});
        break;
      }
      ab.push_back({POS2[a], POS2[HD[ID[a]]]});
      a = P[HD[ID[a]]];
    }
    while (1) {
      if (ID[b] == ID[lcab]) {
        if (b == lcab) break;
        ab2.push_back({POS[NXT[lcab]], POS[b]});
        break;
      }
      ab2.push_back({POS[HD[ID[b]]], POS[b]});
      b = P[HD[ID[b]]];
    }
    while (1) {
      if (ID[c] == ID[lccd]) {
        cd.push_back({POS2[c], POS2[lccd]});
        break;
      }
      cd.push_back({POS2[c], POS2[HD[ID[c]]]});
      c = P[HD[ID[c]]];
    }
    while (1) {
      if (ID[d] == ID[lccd]) {
        if (d == lccd) break;
        cd2.push_back({POS[NXT[lccd]], POS[d]});
        break;
      }
      cd2.push_back({POS[HD[ID[d]]], POS[d]});
      d = P[HD[ID[d]]];
    }
    reverse(ab2.begin(), ab2.end());
    reverse(cd2.begin(), cd2.end());
    for (pair<int, int> &x : ab2) ab.push_back(x);
    for (pair<int, int> &x : cd2) cd.push_back(x);
    reverse(ab.begin(), ab.end());
    reverse(cd.begin(), cd.end());
    int rt = 0;
    while (ab.size() && cd.size()) {
      pair<int, int> &A = ab.back(), &C = cd.back();
      int mn = min(A.second - A.first, C.second - C.first);
      if (get(A.first, A.first + mn) ^ get(C.first, C.first + mn)) {
        rt += getbs(A.first, A.second, C.first, C.second);
        break;
      }
      rt += mn + 1;
      A.first += mn + 1;
      C.first += mn + 1;
      if (A.first > A.second) ab.pop_back();
      if (C.first > C.second) cd.pop_back();
    }
    printf("%d\n", rt);
  }
}