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;
using pii = pair<int, int>;
using pi3 = pair<pii, int>;
const int NN = 6e5 + 1e2;
const int MM = 20;
int n, pa[NN][MM], dep[NN];
int to[NN], head[NN], nxt[NN], E;
inline void add_edge(int u, int v) {
  nxt[E] = head[u];
  to[E] = v;
  head[u] = E++;
}
char s[NN];
pi3 pos[NN];
int rk[NN][MM];
void TreeSuffixArray() {
  for (int i = 1; i <= n; i++) rk[i][0] = rk[i + n][0] = s[i];
  for (int j = 1; j < MM; j++) {
    for (int i = 1; i <= n; i++) {
      int rt = pa[i][j - 1];
      if (~rt) {
        pos[i] = {{rk[i][j - 1], rk[rt][j - 1]}, i};
        pos[i + n] = {{rk[rt + n][j - 1], rk[i + n][j - 1]}, i + n};
      } else {
        pos[i] = {{rk[i][j - 1], 0}, i};
        pos[i + n] = {{0, rk[i + n][j - 1]}, i + n};
      }
    }
    sort(pos + 1, pos + n + n + 1);
    int cnt = 0;
    for (int i = 1; i <= (n << 1); i++) {
      rk[pos[i].second][j] = cnt + 1;
      cnt += (pos[i].first != pos[i + 1].first);
    }
  }
}
void dfs(int u, int dp = 0, int fa = -1) {
  pa[u][0] = fa;
  dep[u] = dp;
  for (int e = head[u]; ~e; e = nxt[e]) {
    if (to[e] == fa) continue;
    dfs(to[e], dp + 1, u);
  }
}
inline int kth(int u, int k) {
  for (int i = MM; i--;)
    if (k & (1 << i)) u = pa[u][i];
  return u;
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  u = kth(u, dep[u] - dep[v]);
  if (u == v) return u;
  for (int i = MM; i--;) {
    if (~pa[u][i] && pa[u][i] != pa[v][i]) {
      u = pa[u][i];
      v = pa[v][i];
    }
  }
  return pa[u][0];
}
inline int Lcp(int a, int b, int len) {
  if (!len) return 0;
  int lcp = 0;
  for (int i = MM; i--;) {
    if (lcp + (1 << i) > len) continue;
    if (rk[a > n ? kth(a - n, len - lcp - (1 << i)) + n : a][i] ==
        rk[b > n ? kth(b - n, len - lcp - (1 << i)) + n : b][i]) {
      if (a <= n) a = pa[a][i];
      if (b <= n) b = pa[b][i];
      lcp += (1 << i);
    }
  }
  return lcp;
}
int Lcp(int a, int b, int c, int d) {
  int u = lca(a, b), v = lca(c, d);
  if (dep[a] - dep[u] < dep[c] - dep[v]) swap(a, c), swap(b, d), swap(u, v);
  int lcp = 0, len, tmp, aa, bb, D;
  len = dep[c] - dep[v];
  lcp += (tmp = Lcp(a, c, len));
  if (tmp != len) return lcp;
  a = kth(a, len);
  aa = dep[a] - dep[u] + 1;
  bb = dep[d] - dep[v] + 1;
  if (aa >= bb) return lcp + Lcp(a, d + n, bb);
  D = kth(d, bb - aa);
  lcp += (tmp = Lcp(a, D + n, aa));
  if (tmp < aa) return lcp;
  aa = dep[b] - dep[u];
  bb = dep[d] - dep[D];
  if (aa > bb)
    b = kth(b, aa - bb);
  else
    d = kth(d, bb - aa);
  return lcp + Lcp(b + n, d + n, min(aa, bb));
}
int main() {
  memset(head, 0xff, sizeof head);
  memset(pa, -1, sizeof pa);
  scanf("%d %s", &n, s + 1);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1);
  for (int j = 1; j < MM; j++) {
    for (int i = 1; i <= n; i++) {
      if (~pa[i][j - 1]) pa[i][j] = pa[pa[i][j - 1]][j - 1];
    }
  }
  TreeSuffixArray();
  int test;
  scanf("%d", &test);
  for (int a, b, c, d; test--;) {
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d\n", Lcp(a, b, c, d));
  }
  return 0;
}