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 mod = 1000000007;
const int logn = 20, N = 300009;
struct edge {
  int s, t, nxt;
} E[N << 1];
int n, m, dep[N], anc[N][logn + 1], Es, adj[N];
long long we, ew, up[N], dn[N], power[N], invPower[N];
char st[N];
long long fastPow(long long x, int n, long long mod) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1) ret = ret * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}
void initHash() {
  we = 31;
  ew = fastPow(we, mod - 2, mod);
  power[0] = invPower[0] = 1;
  for (int i = 1; i < N; i++) {
    power[i] = power[i - 1] * we % mod;
    invPower[i] = invPower[i - 1] * ew % mod;
  }
}
void addEdge(int s, int t) {
  E[Es].s = s;
  E[Es].t = t;
  E[Es].nxt = adj[s];
  adj[s] = Es++;
}
void DFS(int cur, int pre) {
  for (int j = adj[cur]; j >= 0; j = E[j].nxt) {
    int to = E[j].t;
    if (to == pre) continue;
    dep[to] = dep[cur] + 1;
    anc[to][0] = cur;
    for (int i = 1; i <= logn; i++) anc[to][i] = anc[anc[to][i - 1]][i - 1];
    up[to] = (up[cur] * we + (st[to] - 'a' + 1)) % mod;
    dn[to] = (dn[cur] + (st[to] - 'a' + 1) * power[dep[to] - 1]) % mod;
    DFS(to, cur);
  }
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = logn; i >= 0; i--)
    if (dep[anc[x][i]] >= dep[y]) x = anc[x][i];
  if (x == y) return x;
  for (int i = logn; i >= 0; i--)
    if (anc[x][i] != anc[y][i]) x = anc[x][i], y = anc[y][i];
  return anc[x][0];
}
int locate(int u, int L) {
  for (int i = logn; i >= 0; i--)
    if (L >> i & 1) u = anc[u][i];
  return u;
}
void Move(int &u, int v, int &lca, int &len, int L) {
  if (dep[u] - dep[lca] >= L)
    u = locate(u, L);
  else
    lca = u = locate(v, len - L - 1);
  len -= L;
}
long long getHash(int u, int v) {
  long long hs = up[u] - up[v] * power[dep[u] - dep[v]] % mod;
  if (hs < 0) hs += mod;
  return hs;
}
long long revHash(int u, int v) {
  u = anc[u][0];
  v = anc[v][0];
  long long hs = dn[v] - dn[u];
  if (hs < 0) hs += mod;
  hs = hs * invPower[dep[u]] % mod;
  return hs;
}
int LCP(int a, int b, int c, int d) {
  int ret = 0;
  int lca1 = LCA(a, b), lca2 = LCA(c, d);
  int len1 = dep[a] + dep[b] - 2 * dep[lca1] + 1;
  int len2 = dep[c] + dep[d] - 2 * dep[lca2] + 1;
  if (len1 < len2) {
    swap(a, c);
    swap(b, d);
    swap(lca1, lca2);
    swap(len1, len2);
  };
  Move(b, a, lca1, len1, len1 - len2);
  if (dep[a] - dep[lca1] < dep[c] - dep[lca2]) {
    swap(a, c);
    swap(b, d);
    swap(lca1, lca2);
    swap(len1, len2);
  };
  if (dep[c] - dep[lca2] > 0) {
    int L = dep[c] - dep[lca2];
    for (int i = logn; i >= 0; i--)
      if (L >= (1 << i) && getHash(a, anc[a][i]) == getHash(c, anc[c][i])) {
        a = anc[a][i];
        c = anc[c][i];
        L -= (1 << i);
        ret += (1 << i);
      }
    if (L > 0) return ret;
  }
  if (dep[a] > dep[lca1]) {
    int L = dep[a] - dep[lca1];
    int j = 0;
    while ((1 << (j + 1)) <= L) j++;
    int bb = anc[a][j];
    int dd = locate(d, dep[d] - dep[c] - (1 << j));
    if (getHash(a, bb) == revHash(c, dd)) {
      a = locate(a, L - (1 << j));
      c = lca2 = locate(d, dep[d] - dep[c] - L + (1 << j));
      len1 -= L - (1 << j);
      len2 -= L - (1 << j);
      ret += L - (1 << j);
    } else {
      b = lca1 = anc[a][j];
      d = dd;
      len1 = len2 = 1 << j;
    }
    L = (1 << j);
    dd = locate(d, dep[d] - dep[c] - (1 << j));
    assert(dep[a] - dep[lca1] == (1 << j));
    assert(dep[dd] - dep[c] == (1 << j));
    assert(c == lca2);
    assert(dep[a] - dep[lca1] == dep[dd] - dep[c]);
    if (getHash(a, lca1) == revHash(c, dd)) {
      a = lca1;
      c = lca2 = dd;
      len1 -= (1 << j);
      len2 -= (1 << j);
      ret += (1 << j);
    } else {
      for (int i = j - 1; i >= 0; i--)
        if (getHash(a, anc[a][i]) == revHash(c, anc[dd][i]))
          a = anc[a][i], c = anc[dd][i], ret += (1 << i);
        else
          b = anc[a][i], dd = anc[dd][i];
      if (revHash(a, b) == revHash(c, d))
        a = b, c = d, ret++;
      else
        b = a, d = c;
      return ret;
    }
  }
  int L = dep[b] - dep[a];
  if (L > 0) {
    int j = 0;
    while ((1 << (j + 1)) <= L) j++;
    int bb = locate(b, dep[b] - dep[a] - (1 << j));
    int dd = locate(d, dep[d] - dep[c] - (1 << j));
    if (revHash(a, bb) == revHash(c, dd)) {
      a = locate(b, dep[b] - dep[a] - L + (1 << j));
      c = locate(d, dep[d] - dep[c] - L + (1 << j));
      ret += L - (1 << j);
    } else
      b = bb, d = dd;
    L = (1 << j);
    assert(dep[b] - dep[a] == (1 << j));
    assert(dep[d] - dep[c] == (1 << j));
    if (revHash(a, b) == revHash(c, d))
      a = b, c = d, ret += (1 << j);
    else {
      for (int i = j - 1; i >= 0; i--)
        if (revHash(a, anc[b][i]) == revHash(c, anc[d][i]))
          a = anc[b][i], c = anc[d][i], ret += (1 << i);
        else
          b = anc[b][i], d = anc[d][i];
      assert(anc[b][0] == a);
      assert(anc[d][0] == c);
      if (revHash(a, b) == revHash(c, d))
        a = b, c = d, ret++;
      else
        b = a, d = c;
    }
  }
  assert(a == b);
  assert(c == d);
  return ret + (st[b] == st[d]);
}
int main() {
  initHash();
  memset(adj, -1, sizeof(adj));
  scanf("%d", &n);
  scanf("%s", st + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  dep[1] = 1;
  up[1] = dn[1] = st[1] - 'a' + 1;
  DFS(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u1, u2, v1, v2;
    scanf("%d%d%d%d", &u1, &v1, &u2, &v2);
    printf("%d\n", LCP(u1, v1, u2, v2));
  }
  return 0;
}