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;
int n, head[300300], nxt[300300 << 1], to[300300 << 1], fa[300300][22],
    dp[300300];
void add_edge(int x, int y, int id) {
  nxt[id] = head[x], head[x] = id;
  to[id] = y;
}
void dfs(int x, int p = 0) {
  fa[x][0] = p;
  for (int i = 1; i <= 31 - __builtin_clz(n); i++)
    fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == p) continue;
    dp[y] = dp[x] + 1;
    dfs(y, x);
  }
}
int anc(int x, int d) {
  if (!d) return x;
  for (int i = 31 - __builtin_clz(d); i >= 0; i--)
    if (d & (1 << i)) x = fa[x][i];
  return x;
}
int lca(int x, int y) {
  if (dp[x] > dp[y])
    x = anc(x, dp[x] - dp[y]);
  else if (dp[y] > dp[x])
    y = anc(y, dp[y] - dp[x]);
  if (x == y) return x;
  for (int i = 31 - __builtin_clz(dp[x]); i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
int rnk[300300 << 1][22], ord[300300 << 1], dro[300300 << 1], cnt[300300 << 1];
char app[256];
int prf[300300 << 1], suf[300300 << 1];
void build(char *s) {
  memset(app, 0, sizeof app);
  for (int i = 1; i <= n; i++) app[s[i]] = 1;
  for (int i = 0, runs = 0; i < 256; i++)
    if (app[i]) app[i] = ++runs;
  for (int i = 1; i <= n; i++) {
    rnk[i][0] = rnk[i + n][0] = app[s[i]];
  }
  int m = 2 * n;
  for (int j = 1; j <= 31 - __builtin_clz(n); j++) {
    for (int i = 1; i <= n; i++) {
      int p = fa[i][j - 1];
      prf[i] = rnk[i][j - 1], suf[i] = rnk[p][j - 1];
      prf[i + n] = rnk[p ? p + n : p][j - 1], suf[i + n] = rnk[i + n][j - 1];
    }
    for (int i = 0; i <= m; i++) cnt[i] = 0;
    for (int i = 1; i <= m; i++) cnt[suf[i]]++;
    for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
    for (int i = 1; i <= m; i++) dro[cnt[suf[i]]--] = i;
    for (int i = 0; i <= m; i++) cnt[i] = 0;
    for (int i = 1; i <= m; i++) cnt[prf[i]]++;
    for (int i = 1; i <= m; i++) cnt[i] += cnt[i - 1];
    for (int i = m; i >= 1; i--) ord[cnt[prf[dro[i]]]--] = dro[i];
    for (int i = 1, runs = 0; i <= m; i++) {
      if (prf[ord[i]] != prf[ord[i - 1]] || suf[ord[i]] != suf[ord[i - 1]])
        runs++;
      rnk[ord[i]][j] = runs;
    }
  }
}
int lcp(int x, int y, int d) {
  if (!d) return 0;
  int rlt = 0;
  for (int i = 31 - __builtin_clz(d); i >= 0; i--) {
    if (rlt + (1 << i) > d) continue;
    int xx = x <= n ? x : anc(x - n, d - rlt - (1 << i)) + n;
    int yy = y <= n ? y : anc(y - n, d - rlt - (1 << i)) + n;
    if (rnk[xx][i] == rnk[yy][i]) {
      rlt += 1 << i;
      if (x <= n) x = fa[x][i];
      if (y <= n) y = fa[y][i];
    }
  }
  return rlt;
}
int query(int a, int b, int c, int d) {
  int ab = lca(a, b), cd = lca(c, d);
  if (dp[a] - dp[ab] < dp[c] - dp[cd]) {
    a ^= c ^= a ^= c;
    b ^= d ^= b ^= d;
    ab ^= cd ^= ab ^= cd;
  }
  int del = dp[c] - dp[cd];
  int rlt = lcp(a, c, del);
  if (rlt < del) return rlt;
  a = anc(a, del);
  int d1 = dp[a] - dp[ab] + 1, d2 = dp[d] - dp[cd] + 1;
  if (d1 >= d2) return rlt + lcp(a, d + n, d2);
  int md = anc(d, d2 - d1);
  int add = lcp(a, md + n, d1);
  rlt += add;
  if (add < d1) return rlt;
  d1 = dp[b] - dp[ab], d2 = dp[d] - dp[md];
  if (d1 > d2)
    b = anc(b, d1 - d2);
  else
    d = anc(d, d2 - d1);
  return rlt + lcp(b + n, d + n, min(d1, d2));
}
char s[300300];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    add_edge(x, y, i);
    add_edge(y, x, i + n);
  }
  dfs(1);
  build(s);
  int q, a, b, c, d;
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d\n", query(a, b, c, d));
  }
  return 0;
}