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 read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || '9' < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return f * x;
}
const int Mod = (int)(1e9 + 7);
char S[700000 + 5];
vector<int> G[700000 + 5];
int fa[700000 + 5][22];
int p = 59, up[700000 + 5], down[700000 + 5], Powp[700000 + 5], inv[700000 + 5];
int n, dcnt, dfn[700000 + 5], siz[700000 + 5], dep[700000 + 5],
    st[22][700000 + 5];
int Add(int x, int y) {
  x += y;
  return x >= Mod ? x - Mod : x;
}
int Mul(long long x, int y) {
  x *= y;
  return x >= Mod ? x % Mod : x;
}
vector<int> e[700000], ks[700000], kf[700000];
int treedep[700000], son[700000], top[700000];
int f[21][700000];
void po1(int x, int fa, int Dep) {
  treedep[x] = Dep;
  f[0][x] = fa;
  for (int i = 0; i < (int)e[x].size(); ++i) {
    int y = e[x][i];
    if (y == fa) continue;
    po1(y, x, Dep + 1);
    if (treedep[y] > treedep[son[x]]) treedep[x] = treedep[son[x] = y];
  }
}
void po2(int x, int tp) {
  top[x] = tp;
  if (son[x]) po2(son[x], tp);
  for (int i = 0; i < (int)e[x].size(); ++i) {
    int y = e[x][i];
    if (y == f[0][x] || y == son[x]) continue;
    po2(y, y);
  }
}
int highbit[700000];
int kfa(int x, int k) {
  if (!k) return x;
  int r = highbit[k];
  x = f[r][x];
  k -= (1 << r);
  if (dep[x] - k < dep[top[x]])
    return kf[top[x]][dep[top[x]] - (dep[x] - k)];
  else
    return ks[top[x]][(dep[x] - k) - dep[top[x]]];
}
void DFS(int u) {
  dfn[u] = ++dcnt, st[0][dcnt] = u;
  up[u] = Add(Mul(p, up[fa[u][0]]), (S[u] - 'a' + 1));
  down[u] = Add(down[fa[u][0]], Mul((S[u] - 'a' + 1), Powp[dep[u]]));
  for (register int i = 0; i < (int)G[u].size(); i++) {
    register int v = G[u][i];
    if (v == fa[u][0]) continue;
    fa[v][0] = u, dep[v] = dep[u] + 1;
    DFS(v);
    st[0][++dcnt] = u;
  }
  return;
}
unsigned long long Split(int u, int v, int lca, int k) {
  k--;
  unsigned long long ret = 0;
  if (k <= dep[u] - dep[lca]) {
    int tmp = kfa(u, k);
    ret = Add(up[u], Mod - Mul(up[fa[tmp][0]], Powp[k + 1]));
  } else {
    int d = dep[u] - dep[lca], p = dep[u] + dep[v] - 2 * dep[lca] - k,
        tmp = kfa(v, p);
    k -= dep[u] - dep[lca];
    ret = Add(Add(up[u], Mod - Mul(up[lca], Powp[d])),
              Mul(Add(down[tmp], Mod - down[fa[lca][0]]),
                  Mul(inv[dep[lca]], Powp[d])));
  }
  return ret;
}
int lg2[700000 + 5];
void Prepare() {
  for (int i = 2; i <= dcnt; i++) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i <= 19; i++)
    for (int j = 1; j <= dcnt; j++) {
      int x = st[i - 1][j], y = st[i - 1][j + (1 << (i - 1))];
      st[i][j] = (dep[x] < dep[y] ? x : y);
    }
  for (int j = 1; j <= 19; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  return;
}
int Lca(int u, int v) {
  u = dfn[u], v = dfn[v];
  if (u > v) swap(u, v);
  int i = lg2[v - u + 1], a = st[i][u], b = st[i][v - (1 << i) + 1];
  return dep[a] < dep[b] ? a : b;
}
int Pow(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1) ret = Mul(ret, x);
    y >>= 1, x = Mul(x, x);
  }
  return ret;
}
int main() {
  n = read();
  Powp[0] = 1;
  for (int i = 1; i <= n; i++) Powp[i] = Mul(Powp[i - 1], p);
  inv[n] = Pow(Powp[n], Mod - 2);
  for (int i = n - 1; i >= 0; i--) inv[i] = Mul(inv[i + 1], p);
  scanf("%s", S + 1);
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G[u].push_back(v), G[v].push_back(u);
    e[u].push_back(v), e[v].push_back(u);
  }
  DFS(1);
  Prepare();
  po1(1, 0, 1);
  po2(1, 1);
  for (int k = 1; k <= 20; ++k)
    for (int i = 1; i <= n; ++i) f[k][i] = f[k - 1][f[k - 1][i]];
  for (int x = 1; x <= n; ++x)
    if (x == top[x]) {
      int ns = x, nf = x;
      for (int i = 0; i <= treedep[x] - dep[x] + 1; ++i) {
        ks[x].push_back(ns), kf[x].push_back(nf);
        ns = son[ns], nf = f[0][nf];
      }
    }
  for (int i = 1; i <= n; ++i) highbit[i] = log2(i);
  int m = read();
  for (int i = 1; i <= m; i++) {
    int a = read(), b = read(), c = read(), d = read(), lca1 = Lca(a, b),
        lca2 = Lca(c, d);
    int L = 0, R = min(dep[a] + dep[b] - 2 * dep[lca1],
                       dep[c] + dep[d] - 2 * dep[lca2]) +
                   2;
    while (L + 1 < R) {
      int Mid = (L + R) >> 1;
      int tmp1 = Split(a, b, lca1, Mid);
      int tmp2 = Split(c, d, lca2, Mid);
      if (tmp1 == tmp2)
        L = Mid;
      else
        R = Mid;
    }
    printf("%d\n", L);
  }
  return 0;
}