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 _ = 3e5 + 7;
const long long P = 1019260817, sd = 233, inv = 78741179;
struct Edge {
  int end, upEd;
} Ed[_ << 1];
int dfn[_], id[_], sz[_], son[_], top[_], fa[_], dep[_], head[_], cntEd, N, M;
char str[_];
long long hsh[_][2], bse[_], iv[_];
void addEd(int a, int b) {
  Ed[++cntEd] = (Edge){b, head[a]};
  head[a] = cntEd;
}
void dfs1(int x, int p) {
  sz[x] = 1;
  fa[x] = p;
  dep[x] = dep[p] + 1;
  hsh[x][0] = (str[x] + hsh[p][0] * sd) % P;
  hsh[x][1] = (hsh[p][1] + str[x] * bse[dep[x] - 1]) % P;
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != p) {
      dfs1(Ed[i].end, x);
      sz[x] += sz[Ed[i].end];
      if (sz[Ed[i].end] > sz[son[x]]) son[x] = Ed[i].end;
    }
}
void dfs2(int x, int t) {
  static int ts;
  top[x] = t;
  dfn[x] = ++ts;
  id[ts] = x;
  if (!son[x]) return;
  dfs2(son[x], t);
  for (int i = head[x]; i; i = Ed[i].upEd)
    if (Ed[i].end != fa[x] && Ed[i].end != son[x]) dfs2(Ed[i].end, Ed[i].end);
}
vector<pair<int, int> > pl, pr;
vector<pair<int, int> > split(int x, int y) {
  pl.clear();
  pr.clear();
  while (top[x] != top[y])
    if (dep[top[x]] > dep[top[y]]) {
      pl.push_back(pair<int, int>(x, top[x]));
      x = fa[top[x]];
    } else {
      pr.push_back(pair<int, int>(top[y], y));
      y = fa[top[y]];
    }
  pl.push_back(pair<int, int>(x, y));
  reverse(pr.begin(), pr.end());
  pl.insert(pl.end(), pr.begin(), pr.end());
  return pl;
}
long long qry(int x, int fx, int dst) {
  return fx == 1 ? (hsh[x][1] - hsh[fa[id[dfn[x] - dst + 1]]][1] + P) *
                       iv[dep[x] - dst] % P
                 : (hsh[id[dfn[x] + dst - 1]][0] -
                    hsh[fa[x]][0] * bse[dst] % P + P) %
                       P;
}
int val(int x, int fx, int y, int fy, int lim) {
  if (qry(x, fx, lim) == qry(y, fy, lim)) return lim;
  int L = 0, R = lim - 1;
  while (L < R) {
    int mid = (L + R + 1) >> 1;
    qry(x, fx, mid) == qry(y, fy, mid) ? L = mid : R = mid - 1;
  }
  return L;
}
int main() {
  scanf("%d %s", &N, str + 1);
  bse[0] = 1;
  bse[1] = sd;
  iv[0] = 1;
  iv[1] = inv;
  for (int i = 2; i <= N; ++i) {
    bse[i] = bse[i - 1] * sd % P;
    iv[i] = iv[i - 1] * inv % P;
  }
  for (int x, y, i = 1; i < N; ++i) {
    scanf("%d %d", &x, &y);
    addEd(x, y);
    addEd(y, x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  for (scanf("%d", &M); M; --M) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    vector<pair<int, int> > l = split(a, b), r = split(c, d);
    int pl = 0, pr = 0, ans = 0;
    while (pl < (int)l.size() && pr < (int)r.size()) {
      int v1 = dep[l[pl].first] - dep[l[pl].second],
          v2 = dep[r[pr].first] - dep[r[pr].second];
      int l1 = abs(v1), l2 = abs(v2), dst = min(l1, l2) + 1,
          f1 = (v1 < 0 ? -1 : 1), f2 = (v2 < 0 ? -1 : 1);
      int v = val(l[pl].first, f1, r[pr].first, f2, dst);
      ans += v;
      if (dst != v) break;
      if (l1 + 1 == dst)
        ++pl;
      else
        l[pl].first = id[dfn[l[pl].first] - f1 * dst];
      if (l2 + 1 == dst)
        ++pr;
      else
        r[pr].first = id[dfn[r[pr].first] - f2 * dst];
    }
    printf("%d\n", ans);
  }
  return 0;
}