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 int N = 300005;
struct edge {
  int to, next;
} e[N * 2];
int head[N], tot, n, Q;
int sz[N], fa[N], dep[N];
int dfn[N], ed[N], top[N];
int pos[N];
pair<int, int> q1[50], q2[50];
char s[N], t[N * 2];
int cnt[N * 2], x[N * 2], y[N * 2];
int SA[N * 2], rk[N * 2], lg[N * 2];
int st[N * 2][20];
bool cmp(int i, int j, int k, int n) {
  return y[i] != y[j] ||
         ((i + k > n ? -1 : y[i + k]) != (j + k > n ? -1 : y[j + k]));
}
void build_SA(int n) {
  int m = 26;
  for (int i = (int)(1); i <= (int)(n); i++) cnt[x[i] = t[i] - 'a' + 1]++;
  for (int i = (int)(1); i <= (int)(m); i++) cnt[i] += cnt[i - 1];
  for (int i = (int)(n); i >= (int)(1); i--) SA[cnt[x[i]]--] = i;
  for (int k = 1; k < n; k <<= 1) {
    int p = 0;
    for (int i = (int)(n - k + 1); i <= (int)(n); i++) y[++p] = i;
    for (int i = (int)(1); i <= (int)(n); i++)
      if (SA[i] > k) y[++p] = SA[i] - k;
    for (int i = (int)(1); i <= (int)(m); i++) cnt[i] = 0;
    for (int i = (int)(1); i <= (int)(n); i++) cnt[x[y[i]]]++;
    for (int i = (int)(1); i <= (int)(m); i++) cnt[i] += cnt[i - 1];
    for (int i = (int)(n); i >= (int)(1); i--) SA[cnt[x[y[i]]]--] = y[i];
    swap(x, y);
    m = x[SA[1]] = 1;
    for (int i = (int)(2); i <= (int)(n); i++)
      x[SA[i]] = (m += cmp(SA[i - 1], SA[i], k, n));
    if (m == n) break;
  }
  for (int i = (int)(1); i <= (int)(n); i++) rk[SA[i]] = i;
  for (int i = (int)(2); i <= (int)(n); i++) lg[i] = lg[i / 2] + 1;
  int p = 0;
  for (int i = (int)(1); i <= (int)(n); i++)
    if (rk[i] != 1) {
      p -= (p != 0);
      for (; t[i + p] == t[SA[rk[i] - 1] + p]; ++p)
        ;
      st[rk[i]][0] = p;
    }
  for (int i = (int)(1); i <= (int)(19); i++)
    for (int j = (int)(1); j <= (int)(n - (1 << i) + 1); j++)
      st[j][i] = min(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
}
int LCP(int x, int y) {
  x = rk[x];
  y = rk[y];
  if (x == y) return n;
  if (x > y) swap(x, y);
  int k = lg[y - (++x) + 1];
  return min(st[x][k], st[y - (1 << k) + 1][k]);
}
void add(int x, int y) {
  e[++tot] = (edge){y, head[x]};
  head[x] = tot;
}
void dfs1(int x) {
  sz[x] = 1;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x]) {
      fa[e[i].to] = x;
      dep[e[i].to] = dep[x] + 1;
      dfs1(e[i].to);
      sz[x] += sz[e[i].to];
    }
}
void dfs2(int x, int tp) {
  dfn[x] = ed[x] = ++*dfn;
  t[*dfn] = t[2 * n + 1 - (*dfn)] = s[x];
  pos[*dfn] = x;
  int k = 0;
  top[x] = tp;
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x] && sz[e[i].to] > sz[k]) k = e[i].to;
  if (k) {
    dfs2(k, tp);
    ed[x] = ed[k];
  }
  for (int i = head[x]; i; i = e[i].next)
    if (e[i].to != fa[x] && e[i].to != k) dfs2(e[i].to, e[i].to);
}
int getseq(int x, int y, pair<int, int> *q) {
  static pair<int, int> tmp[20];
  static int tp1, tp2;
  tp1 = tp2 = 0;
  for (; top[x] != top[y];)
    if (dep[top[x]] >= dep[top[y]]) {
      q[++tp1] = pair<int, int>(x, top[x]);
      x = fa[top[x]];
    } else {
      tmp[++tp2] = pair<int, int>(top[y], y);
      y = fa[top[y]];
    }
  q[++tp1] = pair<int, int>(x, y);
  reverse(tmp + 1, tmp + tp2 + 1);
  for (int i = (int)(1); i <= (int)(tp2); i++) q[++tp1] = tmp[i];
  return tp1;
}
bool work(pair<int, int> &x, pair<int, int> &y, int &p1, int &p2, int &ans) {
  int len1 = abs(dfn[x.first] - dfn[x.second]) + 1;
  int len2 = abs(dfn[y.first] - dfn[y.second]) + 1;
  int pp1 =
      (dfn[x.first] < dfn[x.second] ? dfn[x.first] : 2 * n + 1 - dfn[x.first]);
  int pp2 =
      (dfn[y.first] < dfn[y.second] ? dfn[y.first] : 2 * n + 1 - dfn[y.first]);
  int L = min(LCP(pp1, pp2), min(len1, len2));
  ans += L;
  if (L == len1)
    ++p1;
  else if (dfn[x.first] < dfn[x.second])
    x.first = pos[dfn[x.first] + L];
  else
    x.first = pos[dfn[x.first] - L];
  if (L == len2)
    ++p2;
  else if (dfn[y.first] < dfn[y.second])
    y.first = pos[dfn[y.first] + L];
  else
    y.first = pos[dfn[y.first] - L];
  return L == min(len1, len2);
}
int main() {
  scanf("%d%s", &n, s + 1);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs1(1);
  dfs2(1, 1);
  build_SA(2 * n);
  scanf("%d", &Q);
  while (Q--) {
    int x1, wzpakking, x2, y2, sz1, sz2, ans = 0;
    scanf("%d%d%d%d", &x1, &wzpakking, &x2, &y2);
    sz1 = getseq(x1, wzpakking, q1);
    sz2 = getseq(x2, y2, q2);
    int p1 = 1, p2 = 1;
    for (; p1 <= sz1 && p2 <= sz2;)
      if (!work(q1[p1], q2[p2], p1, p2, ans)) break;
    printf("%d\n", ans);
  }
}