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;
inline int read() {
  register int x = 0, f = 1;
  register char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + (ch ^ '0');
    ch = getchar();
  }
  return f ? x : -x;
}
const int N = 3e5 + 5, NN = N << 1;
int n, nn, num, head[N];
char _C[N], s[NN];
struct edge {
  int to, next;
} e[NN];
inline void add(int u, int v) { e[++num] = (edge){v, head[u]}, head[u] = num; }
int fa[N], dep[N], siz[N], son[N], top[N], dfn[N], dfc;
void dfs1(int u) {
  dep[u] = dep[fa[u]] + 1;
  siz[u] = 1;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa[u]) continue;
    fa[v] = u;
    dfs1(v);
    siz[u] += siz[v];
    if (siz[son[u]] < siz[v]) son[u] = v;
  }
}
void dfs2(int u) {
  dfn[u] = ++dfc;
  s[dfc] = _C[u];
  if (!top[u]) top[u] = u;
  if (son[u]) {
    top[son[u]] = top[u];
    dfs2(son[u]);
  }
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v);
  }
}
int sa[NN], rnk[NN], height[NN], tmp[NN], A[NN], cntA[NN], B[NN], cntB[NN],
    lg[NN], st[NN][20];
void SA() {
  for (int i = (1), _ed = (nn); i <= _ed; ++i) ++cntA[s[i] - 'a'];
  for (int i = (1), _ed = (100); i <= _ed; ++i) cntA[i] += cntA[i - 1];
  for (int i = (nn), _ed = (1); i >= _ed; --i) sa[cntA[s[i] - 'a']--] = i;
  rnk[sa[1]] = 1;
  for (int i = (2), _ed = (nn); i <= _ed; ++i) {
    rnk[sa[i]] = rnk[sa[i - 1]];
    if (s[sa[i]] ^ s[sa[i - 1]]) ++rnk[sa[i]];
  }
  for (int len = 1; rnk[sa[nn]] < nn; len <<= 1) {
    memset(cntA, 0, sizeof cntA), memset(cntB, 0, sizeof cntB);
    for (int i = (1), _ed = (nn); i <= _ed; ++i) {
      ++cntA[A[i] = rnk[i]];
      ++cntB[B[i] = i + len > nn ? 0 : rnk[i + len]];
    }
    for (int i = (1), _ed = (nn); i <= _ed; ++i) cntB[i] += cntB[i - 1];
    for (int i = (nn), _ed = (1); i >= _ed; --i) tmp[cntB[B[sa[i]]]--] = sa[i];
    for (int i = (1), _ed = (nn); i <= _ed; ++i) cntA[i] += cntA[i - 1];
    for (int i = (nn), _ed = (1); i >= _ed; --i) sa[cntA[A[tmp[i]]]--] = tmp[i];
    rnk[sa[1]] = 1;
    for (int i = (2), _ed = (nn); i <= _ed; ++i) {
      rnk[sa[i]] = rnk[sa[i - 1]];
      if (A[sa[i]] ^ A[sa[i - 1]] || B[sa[i]] ^ B[sa[i - 1]]) ++rnk[sa[i]];
    }
  }
  for (int i = 1, j = 0; i <= nn; ++i) {
    if (j) --j;
    while (s[i + j] == s[sa[rnk[i] - 1] + j]) ++j;
    st[rnk[i]][0] = height[rnk[i]] = j;
  }
  for (int i = (2), _ed = (nn); i <= _ed; ++i) lg[i] = lg[i >> 1] + 1;
  for (int j = (1), _ed = (lg[nn]); j <= _ed; ++j)
    for (int i = (1), _ed = (nn + 1 - (1 << j)); i <= _ed; ++i)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
inline int lcp(int x, int y) {
  if (x == y) return nn - x + 1;
  x = rnk[x], y = rnk[y];
  if (x > y) swap(x, y);
  ++x;
  int k = lg[y - x + 1];
  return min(st[x][k], st[y - (1 << k) + 1][k]);
}
vector<pair<int, int> > work(int x, int y) {
  vector<pair<int, int> > a, b;
  while (top[x] ^ top[y])
    if (dep[top[x]] > dep[top[y]])
      a.push_back(make_pair(nn + 1 - dfn[x], dep[x] - dep[top[x]] + 1)),
          x = fa[top[x]];
    else
      b.push_back(make_pair(dfn[top[y]], dep[y] - dep[top[y]] + 1)),
          y = fa[top[y]];
  if (dep[x] > dep[y])
    a.push_back(make_pair(nn + 1 - dfn[x], dep[x] - dep[y] + 1));
  else
    b.push_back(make_pair(dfn[x], dep[y] - dep[x] + 1));
  reverse(b.begin(), b.end());
  for (int i = (0), _ed = ((int)((b).size()) - 1); i <= _ed; ++i)
    a.push_back(b[i]);
  return a;
}
inline void Main() {
  int a = read(), b = read(), c = read(), d = read();
  vector<pair<int, int> > X = work(a, b), Y = work(c, d);
  int ans = 0;
  for (int i = 0, j = 0, s1 = (int)((X).size()), s2 = (int)((Y).size());
       i < s1 && j < s2;) {
    int l = min(min(X[i].second, Y[j].second), lcp(X[i].first, Y[j].first));
    ans += l;
    X[i].first += l, Y[j].first += l, X[i].second -= l, Y[j].second -= l;
    if (X[i].second && Y[j].second) break;
    if (!X[i].second) ++i;
    if (!Y[j].second) ++j;
  }
  printf("%d\n", ans);
}
int main() {
  n = read();
  scanf("%s", _C + 1);
  nn = n << 1;
  for (int i = (2), _ed = (n); i <= _ed; ++i) {
    int u = read(), v = read();
    add(u, v), add(v, u);
  }
  dfs1(1), dfs2(1);
  for (int i = (1), _ed = (n); i <= _ed; ++i) s[n + i] = s[n - i + 1];
  SA();
  for (int T = (1), _ed = (read()); T <= _ed; ++T) Main();
  return 0;
}