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 = 6e5 + 5;
int n, m, fa[N], dep[N], sz[N], top[N], dfn[N], tim;
vector<int> E[N];
char tmp[N], str[N];
void dfs1(int u, int f) {
  fa[u] = f;
  dep[u] = dep[f] + 1;
  sz[u] = 1;
  for (int v : E[u])
    if (v != f) dfs1(v, u), sz[u] += sz[v];
}
void dfs2(int u, int f) {
  top[u] = f;
  str[dfn[u] = ++tim] = tmp[u];
  int son = 0;
  for (int v : E[u])
    if (v != fa[u] && sz[v] > sz[son]) son = v;
  if (son) dfs2(son, f);
  for (int v : E[u])
    if (v != fa[u] && v != son) dfs2(v, v);
}
int t[N], x[N], y[N], sa[N], rk[N], lg[N], st[20][N];
bool cmp(int i, int j, int k) { return y[i] == y[j] && y[i + k] == y[j + k]; }
void build() {
  int m = 30;
  for (int i = 1; i <= n; ++i) ++t[x[i] = str[i] - 'a' + 1];
  for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
  for (int i = n; i; --i) sa[t[x[i]]--] = i;
  for (int k = 1; k <= n; k <<= 1) {
    int p = 0;
    for (int i = 0; i <= m; ++i) y[i] = 0;
    for (int i = n - k + 1; i <= n; ++i) y[++p] = i;
    for (int i = 1; i <= n; ++i)
      if (sa[i] > k) y[++p] = sa[i] - k;
    for (int i = 0; i <= m; ++i) t[i] = 0;
    for (int i = 1; i <= n; ++i) ++t[x[y[i]]];
    for (int i = 1; i <= m; ++i) t[i] += t[i - 1];
    for (int i = n; i; --i) sa[t[x[y[i]]]--] = y[i];
    swap(x, y);
    x[sa[1]] = p = 1;
    for (int i = 2; i <= n; ++i) x[sa[i]] = cmp(sa[i], sa[i - 1], k) ? p : ++p;
    if (p >= n) break;
    m = p;
  }
  for (int i = 1; i <= n; ++i) rk[sa[i]] = i;
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1, j = 0; i <= n; ++i) {
    if (j) --j;
    while (str[i + j] == str[sa[rk[i] - 1] + j]) ++j;
    st[0][rk[i]] = j;
  }
  for (int i = 1; i <= lg[n]; ++i)
    for (int j = 1; j + (1 << i) - 1 <= n; ++j)
      st[i][j] = min(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
int lcp(int i, int j) {
  if (i == j) return n - i + 1;
  i = rk[i];
  j = rk[j];
  if (i > j) swap(i, j);
  ++i;
  int k = lg[j - i + 1];
  return min(st[k][i], st[k][j - (1 << k) + 1]);
}
vector<pair<int, int> > get(int x, int y) {
  vector<pair<int, int> > foo, bar;
  while (top[x] != top[y])
    if (dep[top[x]] > dep[top[y]])
      foo.push_back({n + 1 - dfn[x], dfn[x] - dfn[top[x]] + 1}), x = fa[top[x]];
    else
      bar.push_back({dfn[top[y]], dfn[y] - dfn[top[y]] + 1}), y = fa[top[y]];
  if (dep[x] > dep[y])
    foo.push_back({n + 1 - dfn[x], dfn[x] - dfn[y] + 1});
  else
    bar.push_back({dfn[x], dfn[y] - dfn[x] + 1});
  while (bar.size()) foo.push_back(bar.back()), bar.pop_back();
  return foo;
}
int main() {
  scanf("%d%s", &n, tmp + 1);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    E[x].push_back(y);
    E[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(1, 1);
  for (int i = 1; i <= n; ++i) str[n + i] = str[n + 1 - i];
  n <<= 1;
  build();
  scanf("%d", &m);
  for (int i = 1, a, b, c, d; i <= m; ++i) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    vector<pair<int, int> > foo = get(a, b), bar = get(c, d);
    int ans = 0;
    for (int i = 0, j = 0; i < foo.size() && j < bar.size();) {
      int k = min(lcp(foo[i].first, bar[j].first),
                  min(foo[i].second, bar[j].second));
      ans += k;
      if (k < min(foo[i].second, bar[j].second)) break;
      if (k == foo[i].second)
        ++i;
      else
        foo[i].first += k, foo[i].second -= k;
      if (k == bar[j].second)
        ++j;
      else
        bar[j].first += k, bar[j].second -= k;
    }
    printf("%d\n", ans);
  }
  return 0;
}