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, h[600005], tot;
char t[600005], s[600005];
struct edge {
  int to, nxt;
} e[600005 << 1];
void add(int x, int y) {
  e[++tot].nxt = h[x];
  h[x] = tot;
  e[tot].to = y;
}
int fa[600005], top[600005], son[600005], sz[600005], dfn[600005], d[600005],
    idx;
void dfs1(int x, int f) {
  fa[x] = f;
  d[x] = d[f] + 1;
  sz[x] = 1;
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].to != f) {
      dfs1(e[i].to, x);
      sz[x] += sz[e[i].to];
      if (sz[e[i].to] > sz[son[x]]) son[x] = e[i].to;
    }
}
void dfs2(int x, int tp) {
  top[x] = tp;
  dfn[x] = ++idx;
  if (!son[x]) return;
  dfs2(son[x], tp);
  for (int i = h[x]; i; i = e[i].nxt)
    if (e[i].to != fa[x] && e[i].to != son[x]) dfs2(e[i].to, e[i].to);
}
struct SA {
  int x[600005], y[600005], sa[600005], c[600005], rk[600005], ht[600005],
      st[600005][20], tk;
  void build(char *ch) {
    int m = 'z';
    n <<= 1;
    for (int i = 1; i <= n; i++) c[x[i] = ch[i]]++;
    for (int i = 1; i <= m; i++) c[i] += c[i - 1];
    for (int i = 1; i <= n; i++) sa[c[x[i]]--] = i;
    for (int k = 1; k <= n; k <<= 1) {
      int num = 0;
      for (int i = n - k + 1; i <= n; i++) y[++num] = i;
      for (int i = 1; i <= n; i++)
        if (sa[i] > k) y[++num] = sa[i] - k;
      for (int i = 1; i <= m; i++) c[i] = 0;
      for (int i = 1; i <= n; i++) c[x[i]]++;
      for (int i = 1; i <= m; i++) c[i] += c[i - 1];
      for (int i = n; i >= 1; i--) sa[c[x[y[i]]]--] = y[i];
      for (int i = 1; i <= n; i++) swap(x[i], y[i]);
      num = x[sa[1]] = 1;
      for (int i = 2; i <= n; i++)
        x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]
                        ? num
                        : ++num);
      m = num;
      if (n == m) break;
    }
    for (int i = 1; i <= n; i++) rk[sa[i]] = i;
    int j = 0;
    for (int i = 1; i <= n; i++) {
      j = max(0, j - 1);
      while (ch[i + j] == ch[sa[rk[i] - 1] + j]) j++;
      ht[rk[i]] = j;
    }
    tk = log2(n);
    for (int i = 1; i <= n; i++) st[i][0] = ht[i];
    for (int j = 1; j <= tk; j++)
      for (int i = 1; i <= n; i++)
        if (i + (1 << j) <= n + 1)
          st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
    n >>= 1;
  }
  int mn(int x, int y) {
    int now = log2(y - x + 1);
    return min(st[x][now], st[y - (1 << now) + 1][now]);
  }
  int lcp(int x, int y) {
    x = rk[x], y = rk[y];
    if (x > y) swap(x, y);
    if (x == y) return 0x3f3f3f3f;
    return mn(x + 1, y);
  }
} sa;
pair<int, int> pt[2][600005];
pair<int, int> l[600005], r[600005];
int w[2];
void path(int x, int y, int op) {
  int ll = 0, rr = 0;
  while (top[x] != top[y]) {
    if (d[top[x]] > d[top[y]]) {
      l[++ll] = make_pair(dfn[x], dfn[top[x]]);
      x = fa[top[x]];
    } else {
      r[++rr] = make_pair(dfn[top[y]], dfn[y]);
      y = fa[top[y]];
    }
  }
  w[op] = 0;
  for (int i = 1; i <= ll; i++) pt[op][++w[op]] = l[i];
  pt[op][++w[op]] = make_pair(dfn[x], dfn[y]);
  for (int i = rr; i >= 1; i--) pt[op][++w[op]] = r[i];
}
void out(int l, int r) {
  if (l <= r)
    for (int i = l; i <= r; i++) putchar(s[i]);
  else
    for (int i = l; i >= r; i--) putchar(s[i]);
}
int calc(int l, int r, int ll, int rr) {
  return min(sa.lcp(l, ll), min(r - l + 1, rr - ll + 1));
}
void check(int &x, int &y) {
  if (x <= y) return;
  x = n * 2 - x, y = n * 2 - y, x++, y++;
}
int solve(int x, int y, int u, int v) {
  path(x, y, 0);
  path(u, v, 1);
  for (int i = 1; i <= w[0]; i++) check(pt[0][i].first, pt[0][i].second);
  for (int i = 1; i <= w[1]; i++) check(pt[1][i].first, pt[1][i].second);
  int ans = 0, i = 1, j = 1;
  while (true) {
    if (j > w[1] || i > w[0]) return ans;
    int w =
        calc(pt[0][i].first, pt[0][i].second, pt[1][j].first, pt[1][j].second);
    int len1 = pt[0][i].second - pt[0][i].first + 1,
        len2 = pt[1][j].second - pt[1][j].first + 1;
    if (w < len1 && w < len2) return ans + w;
    if (w == len1 && w == len2)
      i++, j++;
    else if (w == len1) {
      i++;
      pt[1][j].first += w;
    } else {
      j++;
      pt[0][i].first += w;
    }
    ans += w;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  scanf("%s", t + 1);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  for (int i = 1; i <= n; i++) s[dfn[i]] = t[i];
  for (int i = 1; i <= n; i++) s[n + i] = s[n - i + 1];
  sa.build(s);
  int T;
  scanf("%d", &T);
  while (T--) {
    int x, y, u, v;
    scanf("%d%d%d%d", &x, &y, &u, &v);
    printf("%d\n", solve(x, y, u, v));
  }
  return 0;
}