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 maxn = 3e5, maxlog = 19, alpha = 27,
          mod[2] = {int(1e9 + 21), int(1e9 + 9)};
int n, m, x, y, c, d, tot, ans, l, r, mid, ancestor[2], log_2[maxn << 1 | 1],
    head[maxn + 1], suc[maxn << 1 | 1], to[maxn << 1 | 1],
    parent[maxn + 1][maxlog + 1], son[maxn + 1], top[maxn + 1], depth[maxn + 1],
    height[maxn + 1], highbit[maxn + 1], power[2][maxn + 1], inv[2][maxn + 1],
    order[maxn << 1 | 1], in[maxn + 1], ST[maxn << 1 | 1][maxlog + 1],
    hashsum[4][maxn + 1];
char s[maxn + 2];
vector<int> chain[2][maxn + 1];
inline void read(int &x) {
  x = 0;
  char t = getchar();
  while (!isdigit(t)) t = getchar();
  while (isdigit(t)) {
    x = x * 10 + t - '0';
    t = getchar();
  }
  return;
}
int quick_power(int base, int exponent, int mod) {
  int result = 1;
  while (exponent) {
    if (exponent & 1) result = (long long)result * base % mod;
    base = (long long)base * base % mod;
    exponent >>= 1;
  }
  return result % mod;
}
void get_highbit(void) {
  highbit[0] = -1;
  for (int i = 1; i <= n; ++i) highbit[i] = highbit[i >> 1] + 1;
  return;
}
inline void add_edge(int x, int y) {
  suc[++tot] = head[x];
  to[tot] = y;
  head[x] = tot;
  return;
}
void dfs1(int now) {
  order[in[now] = ++order[0]] = now;
  height[son[now] = now] = depth[now] = depth[parent[now][0]] + 1;
  for (int i = 0; i < 2; ++i) {
    hashsum[i << 1][now] =
        ((long long)hashsum[i << 1][parent[now][0]] * alpha % mod[i] + s[now] -
         'a' + 1) %
        mod[i];
    hashsum[(i << 1) ^ 1][now] =
        (hashsum[(i << 1) ^ 1][parent[now][0]] +
         (long long)(s[now] - 'a' + 1) * power[i][depth[now] - 1] % mod[i]) %
        mod[i];
  }
  for (int i = head[now]; i; i = suc[i])
    if (to[i] != parent[now][0]) {
      parent[to[i]][0] = now;
      for (int j = 1; j <= maxlog; ++j)
        parent[to[i]][j] = parent[parent[to[i]][j - 1]][j - 1];
      dfs1(to[i]);
      if (height[to[i]] > height[son[now]]) son[now] = to[i];
      order[++order[0]] = now;
    }
  height[now] = height[son[now]];
  return;
}
void dfs2(int now, int pos) {
  top[now] = pos;
  if (now == pos) {
    for (int i = 0, t = now; i <= height[now] - depth[now];
         ++i, t = parent[t][0])
      chain[0][now].push_back(t);
    for (int i = 0, t = now; i <= height[now] - depth[now]; ++i, t = son[t])
      chain[1][now].push_back(t);
  }
  for (int i = head[now]; i; i = suc[i])
    if (to[i] != parent[now][0]) dfs2(to[i], son[now] == to[i] ? pos : to[i]);
  return;
}
int query(int now, int step) {
  if (!step) return now;
  now = parent[now][highbit[step]];
  if (!now) return 0;
  step -= (1 << highbit[step]) + depth[now] - depth[top[now]];
  return chain[step < 0][top[now]][abs(step)];
}
int Hash(int opt, int start, int end, int ancestor, int len) {
  if (depth[start] - depth[ancestor] + 1 >= len) {
    int target = query(start, len);
    return (long long)(hashsum[(opt << 1) ^ 1][start] + mod[opt] -
                       hashsum[(opt << 1) ^ 1][target]) *
           inv[opt][depth[target]] % mod[opt];
  } else {
    int newlen = len - (depth[start] - depth[ancestor] + 1),
        target = query(end, depth[end] - depth[ancestor] - newlen);
    return ((long long)(hashsum[(opt << 1) ^ 1][start] + mod[opt] -
                        hashsum[(opt << 1) ^ 1][parent[ancestor][0]]) *
                power[opt][newlen] % mod[opt] *
                inv[opt][depth[parent[ancestor][0]]] % mod[opt] +
            (hashsum[opt << 1][target] + mod[opt] -
             (long long)hashsum[opt << 1][ancestor] *
                 power[opt][depth[target] - depth[ancestor]] % mod[opt])) %
           mod[opt];
  }
}
inline int LCA(int x, int y) {
  x = in[x];
  y = in[y];
  if (x > y) x ^= y ^= x ^= y;
  return depth[ST[x][log_2[y - x + 1]]] <
                 depth[ST[y - (1 << log_2[y - x + 1]) + 1][log_2[y - x + 1]]]
             ? ST[x][log_2[y - x + 1]]
             : ST[y - (1 << log_2[y - x + 1]) + 1][log_2[y - x + 1]];
}
int main() {
  read(n);
  scanf("%s", s + 1);
  power[0][0] = power[1][0] = 1;
  log_2[0] = -1;
  for (int opt = 0; opt < 2; ++opt)
    for (int i = 1; i <= n; ++i)
      power[opt][i] = (long long)power[opt][i - 1] * alpha % mod[opt];
  for (int opt = 0; opt < 2; ++opt) {
    inv[opt][n] = quick_power(power[opt][n], mod[opt] - 2, mod[opt]);
    for (int j = n - 1; ~j; --j)
      inv[opt][j] = (long long)inv[opt][j + 1] * alpha % mod[opt];
  }
  for (int i = 1; i < n; ++i) {
    read(x);
    read(y);
    add_edge(x, y);
    add_edge(y, x);
  }
  get_highbit();
  dfs1(1);
  dfs2(1, 1);
  for (int i = 1; i <= (n << 1); ++i) {
    log_2[i] = log_2[i >> 1] + 1;
    ST[i][0] = order[i];
  }
  for (int i = 1; i <= log_2[n << 1]; ++i)
    for (int j = 1; j + (1 << i) - 1 <= (n << 1); ++j)
      ST[j][i] = (depth[ST[j][i - 1]] < depth[ST[j + (1 << i - 1)][i - 1]]
                      ? ST[j][i - 1]
                      : ST[j + (1 << i - 1)][i - 1]);
  read(m);
  while (m--) {
    read(x);
    read(y);
    read(c);
    read(d);
    ans = l = 0;
    ancestor[0] = LCA(x, y);
    ancestor[1] = LCA(c, d);
    r = min(depth[x] + depth[y] - (depth[ancestor[0]] << 1) + 1,
            depth[c] + depth[d] - (depth[ancestor[1]] << 1) + 1);
    while (l <= r) {
      mid = (l + r) >> 1;
      if (Hash(0, x, y, ancestor[0], mid) == Hash(0, c, d, ancestor[1], mid) &&
          Hash(1, x, y, ancestor[0], mid) == Hash(1, c, d, ancestor[1], mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}