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;
pair<pair<int, int>, int> pos[600010];
int par[600010][18 + 1], ord[600010][18 + 1];
char str[600010];
int to[600010], head[600010], nxt[600010], E;
int dep[600010], p[600010], N;
void add_edge(int u, int v) {
  to[E] = v;
  nxt[E] = head[u];
  head[u] = E++;
  to[E] = u;
  nxt[E] = head[v];
  head[v] = E++;
  return;
}
void dfs(int u) {
  for (int ID = head[u]; ID != -1; ID = nxt[ID]) {
    int v = to[ID];
    if (v == p[u]) continue;
    dep[v] = dep[u] + 1;
    p[v] = u;
    dfs(v);
  }
  return;
}
void Init() {
  for (int i = 1; i <= N; i++)
    for (int j = 0; j <= 18; j++) par[i][j] = -1;
  for (int i = 1; i <= N; i++) par[i][0] = p[i];
  for (int j = 1; j <= 18; j++)
    for (int i = 1; i <= N; i++)
      if (par[i][j - 1] != -1) par[i][j] = par[par[i][j - 1]][j - 1];
  return;
}
void TreeSuffixArray() {
  for (int i = 1; i <= N; i++) {
    ord[i][0] = str[i];
    ord[i + N][0] = str[i];
  }
  for (int j = 1; j <= 18; j++) {
    for (int i = 1; i <= N; i++) {
      int rt = par[i][j - 1];
      if (rt != -1) {
        pos[i] = pair<pair<int, int>, int>(
            pair<int, int>(ord[i][j - 1], ord[rt][j - 1]), i);
        pos[i + N] = pair<pair<int, int>, int>(
            pair<int, int>(ord[rt + N][j - 1], ord[i + N][j - 1]), i + N);
      } else {
        pos[i] = pair<pair<int, int>, int>(pair<int, int>(ord[i][j - 1], 0), i);
        pos[i + N] = pair<pair<int, int>, int>(
            pair<int, int>(0, ord[i + N][j - 1]), i + N);
      }
    }
    sort(pos + 1, pos + N + N + 1);
    int cnt = 0;
    for (int i = 1; i <= N + N; i++) {
      ord[pos[i].second][j] = cnt + 1;
      cnt += (pos[i].first != pos[i + 1].first);
    }
  }
  return;
}
int kth_anscestor(int u, int k) {
  for (int i = 18; i >= 0; i--)
    if ((1 << i) & k) {
      u = par[u][i];
    }
  return u;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  u = kth_anscestor(u, dep[u] - dep[v]);
  if (u == v) return u;
  for (int i = 18; i >= 0; i--)
    if (par[u][i] != -1 && par[u][i] != par[v][i]) {
      u = par[u][i];
      v = par[v][i];
    }
  return p[u];
}
int Lcp(int a, int b, int len) {
  int A, B;
  if (len == 0) return 0;
  int rlt = 0;
  for (int i = 18; i >= 0; i--) {
    if (rlt + (1 << i) > len) continue;
    if (a > N)
      A = kth_anscestor(a - N, len - rlt - (1 << i)) + N;
    else
      A = a;
    if (b > N)
      B = kth_anscestor(b - N, len - rlt - (1 << i)) + N;
    else
      B = b;
    if (ord[A][i] == ord[B][i]) {
      if (a <= N) a = par[a][i];
      if (b <= N) b = par[b][i];
      rlt += (1 << i);
    }
  }
  return rlt;
}
int solve(int a, int b, int c, int d) {
  int x = lca(a, b);
  int y = lca(c, d);
  if (dep[a] - dep[x] < dep[c] - dep[y]) {
    swap(a, c);
    swap(b, d);
    swap(x, y);
  }
  int rlt = 0;
  int len = dep[c] - dep[y];
  int add = Lcp(a, c, len);
  if (add < len) return add;
  rlt += add;
  a = kth_anscestor(a, len);
  int d1 = dep[a] - dep[x] + 1;
  int d2 = dep[d] - dep[y] + 1;
  if (d1 >= d2) return rlt + Lcp(a, d + N, d2);
  int dd = kth_anscestor(d, d2 - d1);
  add = Lcp(a, dd + N, d1);
  rlt += add;
  if (add < d1) return rlt;
  d1 = dep[b] - dep[x];
  d2 = dep[d] - dep[dd];
  if (d1 > d2)
    b = kth_anscestor(b, d1 - d2);
  else
    d = kth_anscestor(d, d2 - d1);
  rlt += Lcp(b + N, d + N, min(d1, d2));
  return rlt;
}
int main() {
  int u, v, M, a, b, c, d;
  memset(head, 0xff, sizeof(head));
  memset(p, 0xff, sizeof(p));
  scanf("%d", &N);
  scanf("%s", str + 1);
  for (int i = 1; i < N; i++) {
    scanf("%d%d", &u, &v);
    add_edge(u, v);
  }
  dfs(1);
  Init();
  TreeSuffixArray();
  for (scanf("%d", &M); M--;) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    printf("%d\n", solve(a, b, c, d));
  }
  return 0;
}