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 pi = std::pair<int, int>;
using vec = std::vector<pi>;
const int N = 300007, P = 1019260817;
char str[N];
int n, fa[N], size[N], dep[N], son[N], top[N], dfn[N], id[N], pw[N], ipw[N],
    h[N][2];
std::vector<int> e[N];
int sgn(int x) { return x < 0 ? -1 : 1; }
int sub(int a, int b) { return a -= b, a += a >> 31 & P; }
int mul(int a, int b) { return 1ll * a * b % P; }
int read() {
  int x = 0, c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) (x *= 10) += c & 15, c = getchar();
  return x;
}
void dfs1(int u, int f) {
  size[u] = 1, dep[u] = dep[fa[u] = f] + 1,
  h[u][0] = (str[u] + 233ll * h[f][0]) % P,
  h[u][1] = (h[f][1] + 1ll * str[u] * pw[dep[u] - 1]) % P;
  for (int v : e[u])
    if (v ^ f)
      dfs1(v, u), size[u] += size[v],
          son[u] = size[v] > size[son[u]] ? v : son[u];
}
void dfs2(int u, int t) {
  static int T;
  top[u] = t, id[dfn[u] = ++T] = u;
  if (son[u]) dfs2(son[u], t);
  for (int v : e[u])
    if (v ^ fa[u] && v ^ son[u]) dfs2(v, v);
}
vec split(int u, int v) {
  vec l, r;
  while (top[u] ^ top[v])
    dep[top[u]] > dep[top[v]] ? (l.push_back({u, top[u]}), u = fa[top[u]])
                              : (r.push_back({top[v], v}), v = fa[top[v]]);
  l.push_back({u, v}), std::reverse(r.begin(), r.end()),
      l.insert(l.end(), r.begin(), r.end());
  return l;
}
int ask(int x, int fx, int d) {
  return fx == 1
             ? mul(sub(h[x][1], h[fa[id[dfn[x] - d + 1]]][1]), ipw[dep[x] - d])
             : sub(h[id[dfn[x] + d - 1]][0], mul(h[fa[x]][0], pw[d]));
}
int cal(int u, int fu, int v, int fv, int lim) {
  if (ask(u, fu, lim) == ask(v, fv, lim)) return lim;
  int l = 1, r = lim - 1;
  for (int mid; l <= r;)
    mid = (l + r) / 2,
    ask(u, fu, mid) == ask(v, fv, mid) ? l = mid + 1 : r = mid - 1;
  return r;
}
void solve() {
  int a = read(), b = read(), c = read(), d = read(), ans = 0;
  vec l = split(a, b), r = split(c, d);
  for (int pl = 0, pr = 0, l1, l2, f1, f2, d, x;
       pl < (int)l.size() && pr < (int)r.size();) {
    l1 = abs(dep[l[pl].first] - dep[l[pl].second]) + 1,
    l2 = abs(dep[r[pr].first] - dep[r[pr].second]) + 1,
    f1 = sgn(dep[l[pl].first] - dep[l[pl].second]),
    f2 = sgn(dep[r[pr].first] - dep[r[pr].second]), d = std::min(l1, l2);
    ans += x = cal(l[pl].first, f1, r[pr].first, f2, d);
    if (d ^ x) break;
    (l1 == d ? ++pl : l[pl].first = id[dfn[l[pl].first] - f1 * d]),
        (l2 == d ? ++pr : r[pr].first = id[dfn[r[pr].first] - f2 * d]);
  }
  printf("%d\n", ans);
}
int main() {
  n = read(), scanf("%s", str + 1), pw[0] = ipw[0] = 1;
  for (int i = 1; i <= n; ++i)
    pw[i] = mul(233, pw[i - 1]), ipw[i] = mul(78741179, ipw[i - 1]);
  for (int i = 1, u, v; i < n; ++i)
    u = read(), v = read(), e[u].push_back(v), e[v].push_back(u);
  dfs1(1, 0), dfs2(1, 1);
  for (int m = read(); m; --m) solve();
}