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 bas = 233;
const int mod1 = 1e9 + 9;
const int mod2 = 998244353;
inline void read(int &x) {
  x = 0;
  int p = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') p = -p;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar();
  x = x * p;
}
const int maxn = 1000005;
int n, tot, ha1[maxn][2], dep[maxn], po1[maxn], po2[maxn], ha2[maxn][2],
    head[maxn], cnt, fa[maxn], siz[maxn], gui[maxn], tail[maxn], son[maxn],
    top[maxn];
struct edge {
  int to, next;
} e[maxn << 1];
char s[maxn];
void add(int x, int y) {
  e[cnt].to = y;
  e[cnt].next = head[x];
  head[x] = cnt++;
}
void dfs1(int u, int pre) {
  siz[u] = 1;
  fa[u] = pre;
  dep[u] = dep[pre] + 1;
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].to == pre) continue;
    dfs1(e[i].to, u);
    siz[u] += siz[e[i].to];
    if (son[u] == -1 || siz[e[i].to] > siz[son[u]]) son[u] = e[i].to;
  }
}
vector<int> vec[maxn];
void dfs2(int u, int t) {
  ha1[u][1] =
      (1LL * ha1[u == t ? 0 : fa[u]][1] * bas % mod1 + (s[u] - '0')) % mod1;
  ha2[u][1] =
      (1LL * ha2[u == t ? 0 : fa[u]][1] * bas % mod2 + (s[u] - '0')) % mod2;
  top[u] = t;
  vec[t].push_back(u);
  gui[u] = vec[t].size() - 1;
  if (son[u] != -1) {
    dfs2(son[u], t);
    tail[u] = tail[son[u]];
    ha1[u][0] = (1LL * ha1[son[u]][0] * bas % mod1 + (s[u] - '0')) % mod1;
    ha2[u][0] = (1LL * ha2[son[u]][0] * bas % mod2 + (s[u] - '0')) % mod2;
  } else {
    tail[u] = u;
    ha1[u][0] = ha2[u][0] = (s[u] - '0');
    return;
  }
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].to == fa[u] || e[i].to == son[u]) continue;
    dfs2(e[i].to, e[i].to);
  }
}
int lca(int a, int b) {
  while (top[a] != top[b]) {
    dep[top[a]] > dep[top[b]] ? a = fa[top[a]] : b = fa[top[b]];
  }
  return dep[a] > dep[b] ? b : a;
}
struct question {
  int l, r, t;
};
int gao(int u, int lc, question st[]) {
  int tp = 0;
  while (1) {
    if (top[u] == top[lc]) {
      st[++tp] = (question){u, lc, 0};
      return tp;
    }
    st[++tp] = (question){u, top[u], 0};
    u = fa[top[u]];
  }
}
int aabs(int x) { return x > 0 ? x : -x; }
question st1[maxn], st2[maxn], st3[maxn], st4[maxn];
int top1, top2, top3, top4;
bool check(int al, int ar, int at, int bl, int br, int bt, int len) {
  if (!at)
    al = (son[al] == -1) ? 0 : son[al];
  else
    al = (top[al] == al) ? 0 : fa[al];
  if (!bt)
    bl = (son[bl] == -1) ? 0 : son[bl];
  else
    bl = (top[bl] == bl) ? 0 : fa[bl];
  int ax1 = (ha1[ar][at] - 1LL * ha1[al][at] * po1[len] % mod1 + mod1) % mod1;
  int bx1 = (ha1[br][bt] - 1LL * ha1[bl][bt] * po1[len] % mod1 + mod1) % mod1;
  int ax2 = (ha2[ar][at] - 1LL * ha2[al][at] * po2[len] % mod2 + mod2) % mod2;
  int bx2 = (ha2[br][bt] - 1LL * ha2[bl][bt] * po2[len] % mod2 + mod2) % mod2;
  return (ax1 == bx1 && ax2 == bx2);
}
int main() {
  po1[0] = po2[0] = 1;
  memset(son, -1, sizeof(son));
  cnt = 1;
  read(n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    po1[i] = 1LL * po1[i - 1] * bas % mod1;
    po2[i] = 1LL * po2[i - 1] * bas % mod2;
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    read(x);
    read(y);
    add(x, y);
    add(y, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  int Q;
  read(Q);
  while (Q--) {
    int a, b, c, d;
    read(a);
    read(b);
    read(c);
    read(d);
    int lcx = lca(a, b);
    int lcy = lca(c, d);
    int ans = 0;
    top1 = gao(a, lcx, st1);
    top2 = gao(c, lcy, st2);
    top3 = gao(b, lcx, st3);
    top4 = gao(d, lcy, st4);
    st3[top3].r = son[st3[top3].r];
    while (top3 && (st3[top3].r == -1 || dep[st3[top3].r] > dep[st3[top3].l]))
      top3--;
    st4[top4].r = son[st4[top4].r];
    while (top4 && (st4[top4].r == -1 || dep[st4[top4].r] > dep[st4[top4].l]))
      top4--;
    while (top3) {
      swap(st3[top3].l, st3[top3].r);
      st1[++top1] = st3[top3];
      st1[top1].t = 1;
      top3--;
    }
    while (top4) {
      swap(st4[top4].l, st4[top4].r);
      st2[++top2] = st4[top4];
      st2[top2].t = 1;
      top4--;
    }
    int nowx = 1, nowy = 1;
    while (nowx <= top1 && nowy <= top2) {
      int al = st1[nowx].l;
      int at = st1[nowx].t;
      int bl = st2[nowy].l;
      int bt = st2[nowy].t;
      int len1 = aabs(dep[st1[nowx].l] - dep[st1[nowx].r]) + 1;
      int len2 = aabs(dep[st2[nowy].l] - dep[st2[nowy].r]) + 1;
      int len = min(len1, len2);
      int l = 1, r = len, res = 0;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (check(al, vec[top[al]][gui[al] + (at ? mid - 1 : 1 - mid)], at, bl,
                  vec[top[bl]][gui[bl] + (bt ? mid - 1 : 1 - mid)], bt, mid))
          l = mid + 1, res = mid;
        else
          r = mid - 1;
      }
      ans += res;
      if (res != len) break;
      if (len1 == len)
        nowx++;
      else
        st1[nowx].l = vec[top[al]][gui[al] + (at ? len : -len)];
      if (len2 == len)
        nowy++;
      else
        st2[nowy].l = vec[top[bl]][gui[bl] + (bt ? len : -len)];
    }
    printf("%d\n", ans);
  }
}