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 = 300005, md = 998244353;
struct node {
  int l, r;
} p1[N], p2[N], q1[N], q2[N];
int n, m, head[N], adj[N * 2], nxt[N * 2], l1, l2, cnt1, cnt2, i, j, k, x, y, z,
    hs1[N], hs2[N], pw[N], dep[N], fa[N], lt, rt, mid, id[N], h[N], tp[N],
    size[N], son[N];
char s[N], ch[N];
int Abs(int a) { return a > 0 ? a : -a; }
int Hash(int l, int r) {
  if (l <= r)
    return (hs1[r] - 1ll * hs1[l - 1] * pw[r - l + 1] % md + md) % md;
  else
    return (hs2[r] - 1ll * hs2[l + 1] * pw[l - r + 1] % md + md) % md;
}
void dfs(int x, int dad) {
  size[x] = 1;
  for (int y = head[x]; y; y = nxt[y])
    if (adj[y] != dad) {
      dep[adj[y]] = dep[x] + 1;
      fa[adj[y]] = x;
      dfs(adj[y], x);
      size[x] += size[adj[y]];
      if (!son[x] || size[adj[y]] > size[son[x]]) son[x] = adj[y];
    }
}
void Dfs(int x, int dad) {
  id[x] = ++i;
  h[i] = x;
  if (son[x]) {
    tp[son[x]] = tp[x];
    Dfs(son[x], x);
  }
  for (int y = head[x]; y; y = nxt[y])
    if (adj[y] != dad && adj[y] != son[x]) {
      tp[adj[y]] = adj[y];
      Dfs(adj[y], x);
    }
}
int main() {
  scanf("%d", &n);
  pw[0] = 1;
  for (i = 1; i <= n; ++i) pw[i] = pw[i - 1] * 131ll % md;
  scanf("%s", s + 1);
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &j, &k);
    adj[i * 2 - 1] = k;
    nxt[i * 2 - 1] = head[j];
    head[j] = i * 2 - 1;
    adj[i * 2] = j;
    nxt[i * 2] = head[k];
    head[k] = i * 2;
  }
  dfs(1, -1);
  tp[1] = 1;
  i = 0;
  Dfs(1, -1);
  for (i = 1; i <= n; ++i) {
    ch[i] = s[h[i]];
    hs1[i] = (hs1[i - 1] * 131ll + ch[i]) % md;
  }
  for (i = n; i >= 1; --i) hs2[i] = (hs2[i + 1] * 131ll + ch[i]) % md;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &i, &j);
    l1 = l2 = 0;
    while (tp[i] != tp[j]) {
      if (dep[tp[i]] > dep[tp[j]]) {
        p1[++l1] = (node){id[i], id[tp[i]]};
        i = fa[tp[i]];
      } else {
        p2[++l2] = (node){id[tp[j]], id[j]};
        j = fa[tp[j]];
      }
    }
    if (dep[i] > dep[j])
      p1[++l1] = (node){id[i], id[j]};
    else
      p2[++l2] = (node){id[i], id[j]};
    cnt1 = 0;
    for (i = 1; i <= l1; ++i) q1[++cnt1] = p1[i];
    for (i = l2; i >= 1; --i) q1[++cnt1] = p2[i];
    scanf("%d%d", &i, &j);
    l1 = l2 = 0;
    while (tp[i] != tp[j]) {
      if (dep[tp[i]] > dep[tp[j]]) {
        p1[++l1] = (node){id[i], id[tp[i]]};
        i = fa[tp[i]];
      } else {
        p2[++l2] = (node){id[tp[j]], id[j]};
        j = fa[tp[j]];
      }
    }
    if (dep[i] > dep[j])
      p1[++l1] = (node){id[i], id[j]};
    else
      p2[++l2] = (node){id[i], id[j]};
    cnt2 = 0;
    for (i = 1; i <= l1; ++i) q2[++cnt2] = p1[i];
    for (i = l2; i >= 1; --i) q2[++cnt2] = p2[i];
    i = j = 1, x = q1[1].l, y = q2[1].l, z = 0;
    while (i <= cnt1 && j <= cnt2) {
      if (Abs(q1[i].r - x) < Abs(q2[j].r - y)) {
        if (Hash(x, q1[i].r) ==
            Hash(y, y + Abs(q1[i].r - x) * (q2[j].l < q2[j].r ? 1 : -1))) {
          z += Abs(q1[i].r - x) + 1;
          y = y + (Abs(q1[i].r - x) + 1) * (q2[j].l < q2[j].r ? 1 : -1);
          if (Abs(y - q2[j].l) + Abs(y - q2[j].r) != Abs(q2[j].l - q2[j].r)) {
            ++j;
            y = q2[j].l;
          }
          ++i;
          x = q1[i].l;
        } else {
          if (ch[x] == ch[y]) {
            lt = 1, rt = Abs(q1[i].r - x) + 1;
            while (lt < rt) {
              mid = (lt + rt + 1) / 2;
              if (Hash(x, x + (mid - 1) * (q1[i].l < q1[i].r ? 1 : -1)) ==
                  Hash(y, y + (mid - 1) * (q2[j].l < q2[j].r ? 1 : -1)))
                lt = mid;
              else
                rt = mid - 1;
            }
            z += lt;
          }
          break;
        }
      } else {
        if (Hash(y, q2[j].r) ==
            Hash(x, x + Abs(q2[j].r - y) * (q1[i].l < q1[i].r ? 1 : -1))) {
          z += Abs(q2[j].r - y) + 1;
          x = x + (Abs(q2[j].r - y) + 1) * (q1[i].l < q1[i].r ? 1 : -1);
          if (Abs(x - q1[i].l) + Abs(x - q1[i].r) != Abs(q1[i].l - q1[i].r)) {
            ++i;
            x = q1[i].l;
          }
          ++j;
          y = q2[j].l;
        } else {
          if (ch[x] == ch[y]) {
            lt = 1, rt = Abs(q2[j].r - y) + 1;
            while (lt < rt) {
              mid = (lt + rt + 1) / 2;
              if (Hash(x, x + (mid - 1) * (q1[i].l < q1[i].r ? 1 : -1)) ==
                  Hash(y, y + (mid - 1) * (q2[j].l < q2[j].r ? 1 : -1)))
                lt = mid;
              else
                rt = mid - 1;
            }
            z += lt;
          }
          break;
        }
      }
    }
    printf("%d\n", z);
  }
  return 0;
}