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, P = 998244353;
int n, m, dep[N], top[N], dfn[N], s[N], son[N], fa[N], dfc, idfn[N], p[N];
int sid[N], pid[N], pre[N], suf[N];
vector<int> e[N];
char str[N];
void dfs1(int u) {
  s[u] = 1, dep[u] = dep[fa[u]] + 1;
  for (auto v : e[u]) {
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs1(v);
    s[u] += s[v];
    if (s[v] > s[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int topf) {
  dfn[u] = ++dfc, idfn[dfc] = u, top[u] = topf;
  if (!son[u]) {
    return;
  }
  dfs2(son[u], topf);
  for (auto v : e[u])
    if (v != fa[u] && v != son[u]) dfs2(v, v);
}
inline int ask(int l, int r) {
  int res;
  if (l <= r)
    res = (pre[r] - 1ll * pre[l - 1] * p[r - l + 1] % P + P) % P;
  else
    res = (suf[r] - 1ll * suf[l + 1] * p[l - r + 1] % P + P) % P;
  return res;
}
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]];
  }
  return dep[x] > dep[y] ? y : x;
}
int jump(int x, int y) {
  while (dfn[x] - dfn[top[x]] + 1 <= y)
    y -= dfn[x] - dfn[top[x]] + 1, x = fa[top[x]];
  return idfn[dfn[x] - y];
}
inline int qry(int x, int y, int k) {
  if (k == 0) return 0;
  if (x == y) return str[x] - 'a';
  int lca = LCA(x, y), now = 0, res = 0;
  bool ok = 0;
  if (x == lca) ok = 1;
  int temp = lca;
  if (!ok) lca = jump(x, dep[x] - dep[lca] - 1);
  while (top[x] != top[lca]) {
    if (now + dfn[x] - dfn[top[x]] + 1 >= k) {
      res = (1ll * res * p[k - now] + ask(dfn[x], dfn[x] - (k - now) + 1)) % P;
      return res;
    } else {
      res =
          (1ll * res * p[dfn[x] - dfn[top[x]] + 1] + ask(dfn[x], dfn[top[x]])) %
          P;
      now += dfn[x] - dfn[top[x]] + 1;
    }
    x = fa[top[x]];
  }
  if (now + dfn[x] - dfn[lca] + 1 >= k) {
    res = (1ll * res * p[k - now] + ask(dfn[x], dfn[x] - (k - now) + 1)) % P;
    return res;
  } else {
    res = (1ll * res * p[dfn[x] - dfn[lca] + 1] + ask(dfn[x], dfn[lca])) % P;
    now += dfn[x] - dfn[lca] + 1;
  }
  static int opt[N], bec[N];
  int tmp = y, len = 0;
  if (!ok)
    lca = temp;
  else
    lca = jump(y, dep[y] - dep[lca] - 1);
  while (top[y] != top[lca]) {
    bec[++len] = top[y];
    y = fa[top[y]];
    opt[len] = y;
  }
  y = tmp;
  for (int i = len; i; i--) {
    if (now + dfn[opt[i]] - dfn[lca] + 1 >= k) {
      res = (1ll * res * p[k - now] + ask(dfn[lca], dfn[lca] + (k - now) - 1)) %
            P;
      return res;
    } else {
      res = (1ll * res * p[dfn[opt[i]] - dfn[lca] + 1] +
             ask(dfn[lca], dfn[opt[i]])) %
            P;
      now += dfn[opt[i]] - dfn[lca] + 1;
      lca = bec[i];
    }
  }
  if (now + dfn[y] - dfn[lca] + 1 >= k) {
    res =
        (1ll * res * p[k - now] + ask(dfn[lca], dfn[lca] + (k - now) - 1)) % P;
    return res;
  } else {
    res = (1ll * res * p[dfn[y] - dfn[lca] + 1] + ask(dfn[lca], dfn[y])) % P;
  }
  return res;
}
int main() {
  scanf("%d%s", &n, str + 1);
  for (int i = 1, x, y; i < n; i++) {
    scanf("%d%d", &x, &y);
    e[x].push_back(y), e[y].push_back(x);
  }
  p[0] = 1;
  for (int i = 1; i <= n; i++) p[i] = 1ll * p[i - 1] * 131 % P;
  dfs1(1);
  dfs2(1, 1);
  for (int i = 1; i <= n; i++)
    pre[i] = (1ll * pre[i - 1] * 131 + str[idfn[i]] - 'a') % P;
  for (int i = n; i >= 1; i--)
    suf[i] = (1ll * suf[i + 1] * 131 + str[idfn[i]] - 'a') % P;
  scanf("%d", &m);
  while (m--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int l = 0, r = min(dep[a] + dep[b] - 2 * dep[LCA(a, b)],
                       dep[c] + dep[d] - 2 * dep[LCA(c, d)]) +
                   1;
    int ans;
    while (l <= r) {
      int mid = l + r >> 1;
      int q1 = qry(a, b, mid), q2 = qry(c, d, mid);
      if (q1 == q2)
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}