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, B = 31, P = 998244853;
int n, m, h[2][N], pw[N], dep[N], sz[N], fa[N], son[N], ind, tin[N], bel[N];
char s[N], _s[N];
int pp, lnk[N], nxt[N * 2], to[N * 2];
void ae(int k1, int k2) { to[++pp] = k2, nxt[pp] = lnk[k1], lnk[k1] = pp; }
int getha(int o, int k1, int k2, int k3 = -1) {
  assert(k1 <= k2);
  if (k3 == -1) k3 = k2 - k1 + 1;
  if (o == 0)
    k2 = k1 + k3 - 1;
  else
    k1 = k2 - k3 + 1;
  if (o == 0)
    return (h[o][k2] - 1LL * h[o][k1 - 1] * pw[k2 - k1 + 1] % P + P) % P;
  else
    return (h[o][k1] - 1LL * h[o][k2 + 1] * pw[k2 - k1 + 1] % P + P) % P;
}
void dfs1(int k1, int k2) {
  dep[k1] = dep[k2] + 1, fa[k1] = k2, sz[k1] = 1;
  for (int i = lnk[k1]; i; i = nxt[i])
    if (to[i] != k2) {
      dfs1(to[i], k1);
      sz[k1] += sz[to[i]];
      if (sz[to[i]] > sz[son[k1]]) son[k1] = to[i];
    }
}
void dfs2(int k1) {
  tin[k1] = ++ind, s[ind] = _s[k1];
  if (son[k1]) {
    bel[son[k1]] = bel[k1];
    dfs2(son[k1]);
  }
  for (int i = lnk[k1]; i; i = nxt[i])
    if (to[i] != fa[k1] && to[i] != son[k1]) {
      bel[to[i]] = to[i];
      dfs2(to[i]);
    }
}
vector<tuple<int, int, int> > getlu(int k1, int k2) {
  vector<tuple<int, int, int> > r[2];
  int o1 = 1, o2 = 0;
  while (bel[k1] != bel[k2]) {
    if (dep[bel[k1]] < dep[bel[k2]]) swap(k1, k2), swap(o1, o2);
    r[o1].emplace_back(tin[bel[k1]], tin[k1], o1);
    k1 = fa[bel[k1]];
  }
  if (dep[k1] < dep[k2]) swap(k1, k2), swap(o1, o2);
  r[o1].emplace_back(tin[k2], tin[k1], o1);
  while (((int)(r[0]).size())) {
    r[1].push_back(r[0].back());
    r[0].pop_back();
  }
  return r[1];
}
int main() {
  pw[0] = 1;
  for (int i = (1); i <= (N - 1); ++i) pw[i] = 1LL * pw[i - 1] * B % P;
  scanf("%d%s", &n, _s + 1);
  for (int i = (2); i <= (n); ++i) {
    int k1, k2;
    scanf("%d%d", &k1, &k2);
    ae(k1, k2), ae(k2, k1);
  }
  dfs1(1, 0);
  bel[1] = 1, dfs2(1);
  for (int i = (1); i <= (n); ++i)
    h[0][i] = (1LL * h[0][i - 1] * B + s[i] - 'a' + 1) % P;
  for (int i = (n); i >= (1); --i)
    h[1][i] = (1LL * h[1][i + 1] * B + s[i] - 'a' + 1) % P;
  scanf("%d", &m);
  for (int _ = (1); _ <= (m); ++_) {
    fprintf(stderr, ">>> %d\n", _);
    int k1, k2, k3, k4;
    scanf("%d%d%d%d", &k1, &k2, &k3, &k4);
    auto r1 = getlu(k1, k2);
    auto r2 = getlu(k3, k4);
    int i = 0, j = 0;
    int ans = 0;
    auto pop = [&](tuple<int, int, int>& k1, int k2) {
      if (get<2>(k1) == 0)
        get<0>(k1) += k2;
      else
        get<1>(k1) -= k2;
    };
    while (i < ((int)(r1).size()) && j < ((int)(r2).size())) {
      int len = min(get<1>(r1[i]) - get<0>(r1[i]) + 1,
                    get<1>(r2[j]) - get<0>(r2[j]) + 1);
      if (getha(get<2>(r1[i]), get<0>(r1[i]), get<1>(r1[i]), len) ==
          getha(get<2>(r2[j]), get<0>(r2[j]), get<1>(r2[j]), len)) {
        pop(r1[i], len);
        pop(r2[j], len);
        ans += len;
      } else {
        int L = 1, R = len, res = 0;
        while (L <= R) {
          int mid = (L + R) >> 1;
          if (getha(get<2>(r1[i]), get<0>(r1[i]), get<1>(r1[i]), mid) ==
              getha(get<2>(r2[j]), get<0>(r2[j]), get<1>(r2[j]), mid)) {
            res = mid, L = mid + 1;
          } else
            R = mid - 1;
        }
        ans += res;
        break;
      }
      if (get<0>(r1[i]) > get<1>(r1[i])) ++i;
      if (get<0>(r2[j]) > get<1>(r2[j])) ++j;
    }
    printf("%d\n", ans);
  }
  return 0;
}