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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int n, q, P[300005][19], p[300005], timer, in[300005], out[300005];
int mod = 1000000009, lvl[300005];
long long hr[300005], hv[300005], hash1, pw[300005], paw[300005], ans1, xar, z;
int aa[300005];
vector<int> v[300005];
int x, y, a, b, c, d, ans[1000005], p1, p2;
int ka[1000005], kb[1000005], kc[1000005], kd[1000005], kp1[1000005],
    kp2[1000005];
vector<pair<int, int> > g[300005];
int w[300005], sz;
int pro[2000005], raod = 0;
int l[1000005], r[1000005], mid[1000005];
string second;
inline int po(int a, int b) {
  ans1 = 1;
  xar = a;
  while (b > 0) {
    if (b % 2 == 1) ans1 = (ans1 * xar) % mod;
    b >>= 1;
    xar = (xar * xar) % mod;
  }
  return ans1;
}
inline void dfs(int x, int par) {
  P[x][0] = par;
  p[x] = par;
  for (int i = 1; i <= 18; i++) P[x][i] = P[P[x][i - 1]][i - 1];
  timer++;
  in[x] = timer;
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i] != par) {
      lvl[v[x][i]] = lvl[x] + 1;
      dfs(v[x][i], x);
    }
  out[x] = timer;
}
inline int lca(int a, int b) {
  if (lvl[a] > lvl[b]) swap(a, b);
  if (in[a] <= in[b] && out[b] <= out[a]) return a;
  for (int i = 18; i >= 0; i--)
    if (P[a][i])
      if (!(in[P[a][i]] <= in[b] && out[b] <= out[P[a][i]])) a = P[a][i];
  return P[a][0];
}
inline void has(int x, int par, int dep) {
  hr[x] = hr[par] * 1013 + aa[x];
  hr[x] %= mod;
  hv[x] = pw[dep] * aa[x] + hv[par];
  hv[x] %= mod;
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] != par) {
      has(v[x][i], x, dep + 1);
    }
  }
}
inline void whatcheck1(int x) {
  if (-lvl[p1] + lvl[a] + 1 >= x) {
    raod++;
    g[a].push_back(make_pair(lvl[a] - x, raod));
  } else {
    z = x - (lvl[a] - lvl[p1]);
    z += lvl[p1] - 1;
    raod++;
    g[b].push_back(make_pair(z, raod));
  }
}
inline void whatcheck2(int x) {
  if (-lvl[p2] + lvl[c] + 1 >= x) {
    raod++;
    g[c].push_back(make_pair(lvl[c] - x, raod));
  } else {
    z = x - (lvl[c] - lvl[p2]);
    z += lvl[p2] - 1;
    raod++;
    g[d].push_back(make_pair(z, raod));
  }
}
inline int check1(int x) {
  hash1 = 0;
  if (-lvl[p1] + lvl[a] + 1 >= x) {
    raod++;
    z = pro[raod];
    hash1 = hv[a] - hv[z] + mod;
    if (hash1 > mod) hash1 -= mod;
    hash1 = hash1 * paw[lvl[z]];
    hash1 %= mod;
  } else {
    hash1 = hv[a] - hv[p1] + mod;
    if (hash1 > mod) hash1 -= mod;
    z = x - (lvl[a] - lvl[p1]);
    hash1 = (hash1 * paw[lvl[p1]]) % mod * pw[z] % mod;
    raod++;
    z = pro[raod];
    z = hr[z] - pw[lvl[z] - lvl[p1] + 1] * hr[p[p1]];
    z %= mod;
    z += mod;
    if (z > mod) z -= mod;
    hash1 += z;
    if (hash1 > mod) hash1 -= mod;
  }
  return hash1;
}
inline int check2(int x) {
  hash1 = 0;
  if (-lvl[p2] + lvl[c] + 1 >= x) {
    raod++;
    z = pro[raod];
    hash1 = hv[c] - hv[z] + mod;
    if (hash1 > mod) hash1 -= mod;
    hash1 = hash1 * paw[lvl[z]];
    hash1 %= mod;
  } else {
    hash1 = hv[c] - hv[p2] + mod;
    if (hash1 > mod) hash1 -= mod;
    z = x - (lvl[c] - lvl[p2]);
    hash1 = (hash1 * paw[lvl[p2]]) % mod * pw[z] % mod;
    raod++;
    z = pro[raod];
    z = hr[z] - pw[lvl[z] - lvl[p2] + 1] * hr[p[p2]];
    z %= mod;
    z += mod;
    if (z > mod) z -= mod;
    hash1 += z;
    if (hash1 > mod) hash1 -= mod;
  }
  return hash1;
}
inline void findall(int x, int par) {
  w[sz] = x;
  sz++;
  for (int i = 0; i < g[x].size(); i++) {
    if (g[x][i].first > 0)
      pro[g[x][i].second] = w[g[x][i].first - 1];
    else
      pro[g[x][i].second] = 0;
  }
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] != par) {
      findall(v[x][i], x);
    }
  }
  sz--;
}
int read() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int x = 0;
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
int main() {
  scanf("%d", &n);
  cin >> second;
  for (int i = 1; i < n; i++) {
    x = read();
    y = read();
    v[x].push_back(y);
    v[y].push_back(x);
  }
  cin >> q;
  for (int i = 1; i <= n; i++) {
    aa[i] = (second[i - 1] - 'a') + 1;
  }
  lvl[1] = 1;
  dfs(1, 0);
  pw[0] = 1;
  paw[0] = 1;
  for (int i = 1; i <= 300000; i++) {
    pw[i] = pw[i - 1] * 1013;
    pw[i] %= mod;
    paw[i] = po(pw[i], mod - 2);
  }
  has(1, 0, 0);
  for (int i = 1; i <= q; i++) {
    ka[i] = read();
    kb[i] = read();
    kc[i] = read();
    kd[i] = read();
    kp1[i] = lca(ka[i], kb[i]);
    kp2[i] = lca(kc[i], kd[i]);
    l[i] = 0;
    r[i] = lvl[ka[i]] + lvl[kb[i]] - 2 * lvl[kp1[i]] + 1;
    r[i] = min(r[i], lvl[kc[i]] + lvl[kd[i]] - 2 * lvl[kp2[i]] + 1);
  }
  for (int uu = 0; uu <= 18; uu++) {
    raod = 0;
    for (int i = 1; i <= n; i++) g[i].clear();
    for (int i = 1; i <= q; i++) {
      if (l[i] > r[i]) continue;
      mid[i] = (l[i] + r[i]) >> 1;
      a = ka[i];
      b = kb[i];
      c = kc[i];
      d = kd[i];
      p1 = kp1[i];
      p2 = kp2[i];
      whatcheck1(mid[i]);
      whatcheck2(mid[i]);
    }
    findall(1, 1);
    raod = 0;
    for (int i = 1; i <= q; i++) {
      if (l[i] > r[i]) continue;
      a = ka[i];
      b = kb[i];
      c = kc[i];
      d = kd[i];
      p1 = kp1[i];
      p2 = kp2[i];
      if (check1(mid[i]) == check2(mid[i])) {
        l[i] = mid[i] + 1;
        ans[i] = mid[i];
      } else {
        r[i] = mid[i] - 1;
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}