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 std::min;
int rank[1200001], sa[1200001], tax[1200001], tp[1200001], n, m, head[300001],
    nxt[600001], b[600001], k, dep[300001], fa[300001], size[300001],
    son[300001], top[300001];
int a[1200001], q, top1, top2, toptem, st[600001][21], loga[600001],
    dfn[300001], now, height[1200001];
std::pair<int, int> tem[300001], t1[300001], t2[300001];
char str[600001];
void push(int s, int t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs1(int x, int f) {
  fa[x] = f;
  size[x] = 1;
  dep[x] = dep[f] + 1;
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f) {
      dfs1(b[i], x);
      size[x] += size[b[i]];
      if (size[b[i]] > size[son[x]]) son[x] = b[i];
    }
}
void dfs2(int x, int t) {
  top[x] = t;
  dfn[x] = ++now;
  if (son[x]) dfs2(son[x], t);
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != fa[x] && b[i] != son[x]) dfs2(b[i], b[i]);
}
void SetSubStr(int x, int y, std::pair<int, int> *a, int &Top) {
  Top = toptem = 0;
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]]) {
      a[++Top] =
          std::make_pair((n << 1) - dfn[x] + 1, (n << 1) - dfn[top[x]] + 1);
      x = fa[top[x]];
    } else {
      tem[++toptem] = std::make_pair(dfn[top[y]], dfn[y]);
      y = fa[top[y]];
    }
  }
  if (dfn[x] < dfn[y])
    a[++Top] = std::make_pair(dfn[x], dfn[y]);
  else
    a[++Top] = std::make_pair((n << 1) - dfn[x] + 1, (n << 1) - dfn[y] + 1);
  for (int i = toptem; i; --i) a[++Top] = tem[i];
}
void Qsort() {
  for (int i = 0; i <= m; i++) tax[i] = 0;
  for (int i = 1; i <= n << 1; i++) tax[rank[i]]++;
  for (int i = 1; i <= m; i++) tax[i] += tax[i - 1];
  for (int i = n << 1; i; --i) sa[tax[rank[tp[i]]]--] = tp[i];
}
void buildsa() {
  m = 1000;
  for (int i = 1; i <= (n << 1); i++) rank[i] = a[i], tp[i] = i;
  Qsort();
  for (int w = 1, p = 1; p < n << 1; m = p, w <<= 1) {
    p = 0;
    for (int i = 1; i <= w; i++) tp[++p] = (n << 1) - w + i;
    for (int i = 1; i <= n << 1; i++)
      if (sa[i] > w) tp[++p] = sa[i] - w;
    Qsort();
    std::swap(rank, tp);
    rank[sa[1]] = p = 1;
    for (int i = 2; i <= n << 1; i++)
      rank[sa[i]] =
          (tp[sa[i]] == tp[sa[i - 1]] && tp[sa[i] + w] == tp[sa[i - 1] + w])
              ? p
              : ++p;
  }
  int k = 0;
  for (int i = 1; i <= n << 1; i++) {
    int j = sa[rank[i] - 1];
    if (k) --k;
    while (a[j + k] == a[i + k]) ++k;
    height[rank[i]] = st[rank[i]][0] = k;
  }
  loga[0] = -1;
  for (int i = 1; i <= n << 1; i++) loga[i] = loga[i >> 1] + 1;
  for (int j = 1; (1 << j) <= n << 1; j++)
    for (int i = 1; i + (1 << j) - 1 <= n << 1; i++)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
}
int LCP(int l, int r) {
  if (l == r) return n << 2;
  l = rank[l];
  r = rank[r];
  if (l > r) std::swap(l, r);
  ++l;
  int k = loga[r - l + 1];
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
void write(int x) {
  if (x > 9) write(x / 10);
  putchar((x % 10) + '0');
}
int main() {
  n = read();
  scanf("%s", str + 1);
  for (int i = 1, s, t; i < n; i++) {
    s = read(), t = read();
    push(s, t);
    push(t, s);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  q = read();
  for (int i = 1; i <= n; i++) a[dfn[i]] = a[(n << 1) - dfn[i] + 1] = str[i];
  buildsa();
  for (int i = 1, a, b, c, d; i <= q; i++) {
    a = read(), b = read(), c = read(), d = read();
    SetSubStr(a, b, t1, top1);
    SetSubStr(c, d, t2, top2);
    int now1 = 1, now2 = 1, l1 = t1[1].first, l2 = t2[1].first, ans = 0;
    for (; now1 <= top1 && now2 <= top2;) {
      int tem = LCP(l1, l2);
      if (!tem) break;
      int length1 = t1[now1].second - l1 + 1,
          length2 = t2[now2].second - l2 + 1;
      tem = min(tem, min(length1, length2));
      ans += tem;
      if (length1 == tem)
        ++now1, l1 = t1[now1].first;
      else
        l1 += tem;
      if (length2 == tem)
        ++now2, l2 = t2[now2].first;
      else
        l2 += tem;
    }
    write(ans), putchar('\n');
  }
}