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 long long mo = 1000000007;
int i, j, k, n, m, flag;
int fa[300010][20], dep[300010];
char p[300010];
vector<int> a[300010];
long long ha[300010], ph[300010], HA[300010];
inline void read(int &x) {
  char p = getchar();
  for (; p < '0' || p > '9'; p = getchar())
    ;
  for (x = 0; p >= '0' && p <= '9'; x = x * 10 + p - 48, p = getchar())
    ;
}
void dfs(int x) {
  int i, j;
  {
    ha[x] = (ha[fa[x][0]] * 31 + p[x] - 'a' + 1) % mo;
    HA[x] = (HA[fa[x][0]] + ph[dep[x]] * (p[x] - 'a' + 1)) % mo;
  }
  for (i = 0; i < a[x].size(); i++) {
    int A = a[x][i];
    if (A == fa[x][0]) continue;
    fa[A][0] = x;
    dep[A] = dep[x] + 1;
    for (j = 1; j <= 19; j++) fa[A][j] = fa[fa[A][j - 1]][j - 1];
    dfs(A);
  }
}
inline int lca(int x, int y) {
  int i;
  if (dep[x] > dep[y]) swap(x, y);
  for (i = 19; i >= 0; i--)
    if (dep[x] + (1 << i) <= dep[y]) y = fa[y][i];
  if (x == y) return x;
  for (i = 19; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
inline int get(int x, int y) {
  int i;
  for (i = 19; i >= 0; i--) {
    int A = 1 << i;
    if (A <= y) y -= A, x = fa[x][i];
  }
  return x;
}
inline long long cal(int x, int y) {
  long long an = (HA[x] - HA[y]) % mo * ph[n - dep[y]] % mo;
  return (an + mo) % mo;
}
inline long long Cal(int x, int y) {
  long long an =
      (ha[x] - ha[y] * ph[dep[x] - dep[y]] % mo) % mo * ph[n + 1] % mo;
  return (an + mo) % mo;
}
inline int suan(int x, int y, int lc) {
  int s1 = dep[x] - dep[lc] + 1, s2 = dep[y] - dep[lc] + 1;
  return s1 + s2 - 1;
}
inline int gao1(int &x, int &y, int k) {
  int i, s = 0;
  for (i = 19; i >= 0; i--)
    if ((1 << i) <= k) {
      if (cal(x, fa[x][i]) == cal(y, fa[y][i]))
        x = fa[x][i], y = fa[y][i], s += 1 << i, k -= 1 << i;
    }
  return s;
}
inline int gao2(int &x, int ci, int &y, int k) {
  int i, s = 0, ro = get(x, ci);
  for (i = 19; i >= 0; i--) {
    int A = 1 << i;
    if (s + A <= k) {
      int xx = get(x, ci - A - s);
      if (Cal(xx, ro) == cal(y, fa[y][i])) y = fa[y][i], s += A, ro = xx;
    }
  }
  return s;
}
inline long long gao3(int &x, int ci, int &y, int Ci, int k) {
  int i, s = 0, ro = get(x, ci), roo = get(y, Ci);
  for (i = 19; i >= 0; i--) {
    int A = 1 << i;
    if (A + s <= k) {
      int xx = get(x, ci - A - s), yy = get(y, Ci - A - s);
      if (Cal(xx, ro) == Cal(yy, roo)) s += A, ro = xx, roo = yy;
    }
  }
  return s;
}
inline int work(int x, int y, int xx, int yy) {
  int a1 = lca(x, y), a2 = lca(xx, yy);
  int s1 = dep[x] - dep[a1] + 1, s2 = dep[xx] - dep[a2] + 1;
  int ss1 = suan(x, y, a1), ss2 = suan(xx, yy, a2);
  int len = min(ss1, ss2);
  if (s1 > s2) {
    swap(x, xx);
    swap(y, yy);
    swap(a1, a2);
    swap(s1, s2);
    swap(ss1, ss2);
  }
  s2 = min(s2, len);
  if (flag) printf("1 ");
  int A = gao1(x, xx, s1);
  if (A < s1) return A;
  if (flag) printf("2 ");
  int B = gao2(y, ss1 - s1, xx, s2 - s1);
  if (B < s2 - s1) return A + B;
  if (flag) printf("3 ");
  int C = gao3(y, ss1 - s2, yy, ss2 - s2, len - s2);
  return A + B + C;
}
int main() {
  scanf("%d", &n);
  scanf("%s", p + 1);
  ph[0] = 1;
  for (i = 1; i <= n + 1; i++) ph[i] = ph[i - 1] * 31 % mo;
  for (i = 1; i <= n - 1; i++) {
    int x, y;
    read(x), read(y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  dep[1] = 1;
  dfs(1);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    int x, y, A, B;
    read(x), read(y), read(A), read(B);
    if (flag) printf("%I64u %I64u ", Cal(x, fa[x][0]), Cal(y, fa[y][0]));
    printf("%d\n", work(x, y, A, B));
  }
  return 0;
}