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 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, m, fa[N], son[N], siz[N], dep[N], top[N], dfn[N], tim = 0, ht[N], rnk[N],
                                                         lg2[N], st[20][N];
char s[N], tmp[N];
vector<int> E[N];
bool cmp(int *r, int a, int b, int l) {
  return r[a] == r[b] && r[a + l] == r[b + l];
}
int query(int l, int r) {
  int k = lg2[r - l + 1];
  return min(st[k][l], st[k][r - (1 << k) + 1]);
}
int lcp(int x, int y) {
  if (x == y) return n - x + 1;
  if (rnk[x] > rnk[y]) swap(x, y);
  return query(rnk[x] + 1, rnk[y]);
}
void build() {
  static int ws[N], wv[N], x[N], y[N], sa[N];
  int m = 128;
  for (int i = 0; i <= m; i++) ws[i] = 0;
  for (int i = 1; i <= n; i++) ws[x[i] = s[i]]++;
  for (int i = 1; i <= m; i++) ws[i] += ws[i - 1];
  for (int i = n; i; i--) sa[ws[x[i]]--] = i;
  for (int j = 1;; j <<= 1) {
    int p = 0;
    for (int i = n - j + 1; i <= n; i++) y[++p] = i;
    for (int i = 1; i <= n; i++)
      if (sa[i] > j) y[++p] = sa[i] - j;
    for (int i = 1; i <= n; i++) wv[i] = x[y[i]];
    for (int i = 0; i <= m; i++) ws[i] = 0;
    for (int i = 1; i <= n; i++) ws[wv[i]]++;
    for (int i = 1; i <= m; i++) ws[i] += ws[i - 1];
    for (int i = n; i; i--) sa[ws[wv[i]]--] = y[i];
    swap(x, y);
    x[sa[1]] = p = 1;
    for (int i = 2; i <= n; i++)
      x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p : ++p;
    if (p == n) break;
    m = p;
  }
  for (int i = 1; i <= n; i++) rnk[sa[i]] = i;
  for (int i = 1, j, k = 0; i <= n; ht[rnk[i++]] = k)
    for (k ? k-- : 0, j = sa[rnk[i] - 1]; s[i + k] == s[j + k]; k++)
      ;
  for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1;
  for (int i = 1; i <= n; i++) st[0][i] = ht[i];
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);
}
void dfs1(int u, int ff) {
  fa[u] = ff, siz[u] = 1, dep[u] = dep[ff] + 1;
  for (auto v : E[u])
    if (v ^ ff) {
      dfs1(v, u), siz[u] += siz[v];
      if (siz[son[u]] < siz[v]) son[u] = v;
    }
}
void dfs2(int u, int tp) {
  top[u] = tp;
  s[dfn[u] = ++tim] = tmp[u];
  if (son[u]) dfs2(son[u], tp);
  for (auto v : E[u])
    if (v != fa[u] && v != son[u]) dfs2(v, v);
}
vector<pair<int, int> > get(int u, int v) {
  vector<pair<int, int> > A, B;
  while (top[u] != top[v]) {
    if (dep[top[u]] > dep[top[v]])
      A.push_back(make_pair(n - dfn[u] + 1, dfn[u] - dfn[top[u]] + 1)),
          u = fa[top[u]];
    else
      B.push_back(make_pair(dfn[top[v]], dfn[v] - dfn[top[v]] + 1)),
          v = fa[top[v]];
  }
  if (dep[u] > dep[v])
    A.push_back(make_pair(n - dfn[u] + 1, dfn[u] - dfn[v] + 1));
  else
    B.push_back(make_pair(dfn[u], dfn[v] - dfn[u] + 1));
  while (!B.empty()) A.push_back(B.back()), B.pop_back();
  return A;
}
int main() {
  n = gi();
  scanf("%s", tmp + 1);
  for (int i = 1, u, v; i < n; i++)
    u = gi(), v = gi(), E[u].push_back(v), E[v].push_back(u);
  dfs1(1, 0), dfs2(1, 1);
  for (int i = 1; i <= n; i++) s[n + n - i + 1] = s[i];
  n <<= 1;
  s[n + 1] = '\0';
  build();
  m = gi();
  while (m--) {
    int a = gi(), b = gi(), c = gi(), d = gi(), ans = 0;
    vector<pair<int, int> > A = get(a, b), B = get(c, d);
    for (int i = 0, j = 0; i < int(A.size()) && j < int(B.size());) {
      int k = min(lcp(A[i].first, B[j].first), min(A[i].second, B[j].second));
      ans += k;
      if (k < min(A[i].second, B[j].second)) break;
      if (A[i].second == k)
        ++i;
      else
        A[i].first += k, A[i].second -= k;
      if (B[j].second == k)
        ++j;
      else
        B[j].first += k, B[j].second -= k;
    }
    cout << ans << '\n';
  }
  return 0;
}