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, letters = 26, m;
struct edgeType {
  int to, nxt;
} e[300010 << 1];
int head[300010];
int parent[300010];
int siz[300010], depth[300010];
int hs[300010], act[300010];
int qhyP[300010], zygP[300010];
int len;
char s[300010];
int str[600010];
int SA[600010], rk[600010];
int lastSA[600010], key[600010];
int cnt[600010];
int height[600010][22];
int qhy[300010], zyg[300010];
int lx[300010], fd[300010];
void add_edge(int u, int v, int x) {
  e[x].to = v;
  e[x].nxt = head[u];
  head[u] = x;
}
void get_string_and_edges() {
  int i, u, v;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v, i * 2 - 1);
    add_edge(v, u, i * 2);
  }
}
void radix_sort(int upperbound, int L) {
  int i;
  int tmp0, tmp1;
  memset(cnt, 0, sizeof(int) * (upperbound + 3));
  for (i = 1; i <= len; i++) cnt[key[i]]++;
  for (i = 1; i <= upperbound; i++) cnt[i] += cnt[i - 1];
  for (i = len; i > 0; i--) SA[cnt[key[lastSA[i]]]--] = lastSA[i];
  for (i = 1, tmp0 = -1; i <= len; i++) {
    tmp1 = SA[i] + L <= len ? key[SA[i] + L] : -1;
    rk[SA[i]] = rk[SA[i - 1]] + (key[SA[i]] != key[SA[i - 1]] || tmp0 != tmp1);
    tmp0 = tmp1;
  }
}
int min(int x, int y) { return x < y ? x : y; }
int tmp;
int min_st(int l, int r) {
  if (l == r) return len - SA[l] + 1;
  if (r < l) l ^= r ^= l ^= r;
  l++;
  tmp = (int)(log(r - l + 1) / log(2));
  return min(height[l][tmp], height[r - (1 << tmp) + 1][tmp]);
}
void suffix_sort() {
  int i, j, k;
  for (i = 1; i <= len; i++) {
    key[i] = str[i];
    lastSA[i] = i;
  }
  radix_sort(26, 0);
  for (i = 1; i < len; i <<= 1) {
    for (j = 1; j <= i; j++) lastSA[j] = len - j + 1;
    for (k = 1; k <= len; k++) {
      if (SA[k] > i) lastSA[j++] = SA[k] - i;
      key[k] = rk[k];
    }
    radix_sort(len, i);
  }
  for (i = 1, k = 0; i <= len; i++) {
    if (rk[i] == 1) continue;
    j = SA[rk[i] - 1];
    while (i + k <= len && j + k <= len && str[i + k] == str[j + k]) k++;
    height[rk[i]][0] = k;
    k -= (k > 0);
  }
  for (i = 1; (1 << i) <= len; i++)
    for (j = 2; j + (1 << i) - 1 <= len; j++)
      height[j][i] = min(height[j][i - 1], height[j + (1 << (i - 1))][i - 1]);
}
void dfs0(int x, int p) {
  int i;
  siz[x] = 1;
  depth[x] = depth[p] + 1;
  parent[x] = p;
  for (i = head[x]; i; i = e[i].nxt)
    if (e[i].to != p) {
      dfs0(e[i].to, x);
      siz[x] += siz[e[i].to];
      if (siz[hs[x]] < siz[e[i].to]) hs[x] = e[i].to;
    }
}
void dfs1(int x, int p) {
  int i;
  str[++len] = s[x] - 'a' + 1;
  qhyP[x] = len;
  if (hs[x]) {
    act[hs[x]] = act[x];
    dfs1(hs[x], x);
  }
  for (i = head[x]; i; i = e[i].nxt)
    if (e[i].to != p && e[i].to != hs[x]) {
      act[e[i].to] = e[i].to;
      dfs1(e[i].to, x);
    }
}
void dfs2(int x, int p) {
  int i;
  for (i = head[x]; i; i = e[i].nxt)
    if (e[i].to != p && e[i].to != hs[x]) {
      dfs2(e[i].to, x);
    }
  if (hs[x]) dfs2(hs[x], x);
  str[++len] = s[x] - 'a' + 1;
  zygP[x] = len;
}
void standing_by() {
  get_string_and_edges();
  dfs0(1, 0);
  dfs1(act[1] = 1, 0);
  dfs2(1, 0);
  suffix_sort();
}
void get_link(int u, int v) {
  int i;
  qhy[0] = zyg[0] = 0;
  while (act[u] != act[v]) {
    if (depth[act[u]] > depth[act[v]]) {
      zyg[++zyg[0]] = u;
      zyg[++zyg[0]] = act[u];
      u = parent[act[u]];
    } else {
      qhy[++qhy[0]] = v;
      qhy[++qhy[0]] = act[v];
      v = parent[act[v]];
    }
  }
  if (depth[u] < depth[v]) {
    qhy[++qhy[0]] = v;
    qhy[++qhy[0]] = u;
  } else {
    zyg[++zyg[0]] = u;
    zyg[++zyg[0]] = v;
  }
}
void complete() {
  int i, j, u, v, k;
  int ans;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    get_link(u, v);
    lx[0] = 0;
    for (j = 1; j <= zyg[0]; j++) lx[++lx[0]] = zygP[zyg[j]];
    for (j = qhy[0]; j > 0; j--) lx[++lx[0]] = qhyP[qhy[j]];
    scanf("%d%d", &u, &v);
    get_link(u, v);
    fd[0] = 0;
    for (j = 1; j <= zyg[0]; j++) fd[++fd[0]] = zygP[zyg[j]];
    for (j = qhy[0]; j > 0; j--) fd[++fd[0]] = qhyP[qhy[j]];
    ans = 0;
    for (u = 1, v = 1; u <= lx[0] && v <= fd[0];) {
      k = min_st(rk[lx[u]], rk[fd[v]]);
      k = min(k, lx[u + 1] - lx[u] + 1);
      k = min(k, fd[v + 1] - fd[v] + 1);
      ans += k;
      if (k < lx[u + 1] - lx[u] + 1 && k < fd[v + 1] - fd[v] + 1)
        break;
      else {
        lx[u] += k;
        fd[v] += k;
        if (lx[u] > lx[u + 1]) u += 2;
        if (fd[v] > fd[v + 1]) v += 2;
      }
    }
    printf("%d\n", ans);
  }
}
int main() {
  standing_by();
  complete();
  return 0;
}