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;
char s[300005];
int n, cnt, p[300005], to[600005], nexti[600005];
int fa[300005], son[300005], dep[300005], size[300005], top[300005],
    dfsx[300005], st[300005];
void dfs(int x, int lasti) {
  son[x] = 0;
  size[x] = 1;
  for (int i = p[x]; i != -1; i = nexti[i])
    if (to[i] != lasti) {
      fa[to[i]] = x;
      dep[to[i]] = dep[x] + 1;
      dfs(to[i], x);
      size[x] += size[to[i]];
      if (!son[x] || size[to[i]] > size[son[x]]) son[x] = to[i];
    }
}
void DFS(int x, int lasti) {
  st[x] = ++cnt;
  dfsx[cnt] = x;
  if (son[x]) top[son[x]] = top[x], DFS(son[x], x);
  for (int i = p[x]; ~i; i = nexti[i])
    if (to[i] != lasti && to[i] != son[x]) top[to[i]] = to[i], DFS(to[i], x);
}
int pw[300005], pre[300005], suf[300005];
inline int gethash(int l, int r) {
  if (l < r)
    return (pre[r] - 1LL * pre[l - 1] * pw[r - l + 1] % 998244353 + 998244353) %
           998244353;
  else
    return (suf[r] - 1LL * suf[l + 1] * pw[l - r + 1] % 998244353 + 998244353) %
           998244353;
}
struct Seg {
  int l, r;
  int size() { return abs(r - l) + 1; }
  Seg(int l = 0, int r = 0) : l(l), r(r) {}
} x[233], y[233];
int getpath(int a, int b, Seg *seg) {
  static Seg l[233], r[233];
  int lt = 0, rt = 0;
  while (top[a] != top[b]) {
    if (dep[top[a]] > dep[top[b]])
      l[++lt] = Seg(st[a], st[top[a]]), a = fa[top[a]];
    else
      r[++rt] = Seg(st[top[b]], st[b]), b = fa[top[b]];
  }
  if (dep[a] > dep[b])
    l[++lt] = Seg(st[a], st[b]);
  else
    r[++rt] = Seg(st[a], st[b]);
  int segn = 0;
  for (int i = 1; i <= lt; ++i) seg[++segn] = l[i];
  for (int i = rt; i >= 1; --i) seg[++segn] = r[i];
  return segn;
}
inline void get_interval(const Seg &s, int len, int &l, int &r) {
  if (s.l < s.r)
    l = s.l, r = l + len - 1;
  else
    l = s.l, r = l - len + 1;
}
inline void reduce(Seg *s, int &i, int len) {
  if (s[i].size() == len)
    s[i++] = Seg();
  else if (s[i].l < s[i].r)
    s[i].l += len;
  else
    s[i].l -= len;
}
int query(int a, int b, int c, int d) {
  int xn = getpath(a, b, x);
  int yn = getpath(c, d, y);
  int res = 0;
  int idx = 1, idy = 1;
  while (idx <= xn && idy <= yn) {
    int len = std::min(x[idx].size(), y[idy].size()), l, r;
    get_interval(x[idx], len, l, r);
    int hx = gethash(l, r);
    get_interval(y[idy], len, l, r);
    int hy = gethash(l, r);
    if (hx == hy) {
      reduce(x, idx, len);
      reduce(y, idy, len);
      res += len;
    } else {
      int ans = 0;
      int L = 1, R = len - 1;
      while (L <= R) {
        len = (L + R) >> 1;
        get_interval(x[idx], len, l, r);
        hx = gethash(l, r);
        get_interval(y[idy], len, l, r);
        hy = gethash(l, r);
        if (hx == hy) {
          L = len + 1;
          ans = len;
        } else
          R = len - 1;
      }
      res += ans;
      break;
    }
  }
  return res;
}
int main() {
  scanf("%d%s", &n, s + 1);
  memset(p, -1, sizeof p);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    cnt++, to[cnt] = v, nexti[cnt] = p[u], p[u] = cnt;
    cnt++, to[cnt] = u, nexti[cnt] = p[v], p[v] = cnt;
  }
  dep[1] = 1;
  dfs(1, -1);
  cnt = 0;
  DFS(1, 1);
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = 1LL * pw[i - 1] * 29 % 998244353;
  for (int i = 1; i <= n; ++i)
    pre[i] = (1LL * pre[i - 1] * 29 + s[dfsx[i]] - 'a' + 1) % 998244353;
  for (int i = n; i >= 1; --i)
    suf[i] = (1LL * suf[i + 1] * 29 + s[dfsx[i]] - 'a' + 1) % 998244353;
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", query(a, b, c, d));
  }
  return 0;
}