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 MAXN = 3e5 + 5;
const int Base = 19260817, MOD = 998244353;
int n, m;
char s[MAXN];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') && (f = -f), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
inline int explus(const int &a, const int &b) {
  return a + b >= MOD ? a + b - MOD : a + b;
}
inline void Explus(int &a, const int &b) {
  a = a + b >= MOD ? a + b - MOD : a + b;
}
inline int exminus(const int &a, const int &b) {
  return a - b < 0 ? a - b + MOD : a - b;
}
inline void Exminus(int &a, const int &b) {
  a = a - b < 0 ? a - b + MOD : a - b;
}
inline int expow(int n, int k) {
  int ans = 1;
  for (; k; k >>= 1, n = 1ll * n * n % MOD)
    (k & 1) && (ans = 1ll * ans * n % MOD);
  return ans;
}
const int iBase = expow(Base, MOD - 2);
int head[MAXN], trump;
struct Edge {
  int to, next;
  Edge(int u = 0, int v = 0) : to(v), next(head[u]){};
} e[MAXN << 1];
inline void addedge(int u, int v) {
  e[++trump] = Edge(u, v);
  head[u] = trump;
  e[++trump] = Edge(v, u);
  head[v] = trump;
}
int dep[MAXN], size[MAXN], father[MAXN];
int son[MAXN], top[MAXN], dfn[MAXN], rev[MAXN];
int Hash[MAXN][2], qpow[MAXN], inv[MAXN];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  father[u] = fa;
  size[u] = 1;
  Hash[u][0] = explus(1ll * Hash[fa][0] * Base % MOD, s[u] - 'a' + 3);
  Hash[u][1] =
      explus(Hash[fa][1], 1ll * (s[u] - 'a' + 3) * qpow[dep[u] - 1] % MOD);
  for (register int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
    size[u] += size[v];
    if (size[son[u]] < size[v]) son[u] = v;
  }
}
void df5(int u, int link) {
  top[u] = link;
  rev[dfn[u] = ++dfn[0]] = u;
  if (son[u]) df5(son[u], link);
  for (register int i = head[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (top[v]) continue;
    df5(v, v);
  }
}
inline int lca(int u, int v) {
  for (; top[u] ^ top[v];
       dep[top[u]] > dep[top[v]] ? u = father[top[u]] : v = father[top[v]])
    ;
  return dep[u] < dep[v] ? u : v;
}
inline int kthfa(int u, int k) {
  while (dep[u] - dep[top[u]] + 1 <= k && u != 1) {
    k -= dep[u] - dep[top[u]] + 1;
    u = father[top[u]];
  }
  return rev[dfn[u] - k];
}
int getHash(int u, int v, int lca, int len) {
  if (dep[u] - dep[lca] + 1 >= len) {
    int d = kthfa(u, len - 1);
    return exminus(Hash[u][0], 1ll * Hash[father[d]][0] * qpow[len] % MOD);
  }
  int Hsh1 = exminus(Hash[u][0], 1ll * Hash[father[lca]][0] *
                                     qpow[dep[u] - dep[lca] + 1] % MOD);
  int d = kthfa(v, dep[u] + dep[v] - 2 * dep[lca] + 1 - len);
  return explus(Hsh1, 1ll * exminus(Hash[d][1], Hash[lca][1]) * inv[dep[lca]] %
                          MOD * qpow[dep[u] - dep[lca] + 1] % MOD);
}
int main() {
  register int i;
  n = read();
  qpow[0] = 1;
  inv[0] = 1;
  scanf("%s", s + 1);
  for (i = 1; i < n; ++i) addedge(read(), read());
  for (i = 1; i <= n; ++i)
    qpow[i] = 1ll * qpow[i - 1] * Base % MOD,
    inv[i] = 1ll * inv[i - 1] * iBase % MOD;
  dfs(1, 0);
  df5(1, 1);
  m = read();
  while (m--) {
    int u1 = read(), v1 = read(), u2 = read(), v2 = read();
    int l1 = lca(u1, v1), l2 = lca(u2, v2);
    int l = 1,
        r = min(dep[u1] + dep[v1] + 1 - 2 * dep[l1],
                dep[u2] + dep[v2] + 1 - 2 * dep[l2]),
        mid, ans = 0;
    while (l <= r) {
      mid = l + r >> 1;
      if (getHash(u1, v1, l1, mid) == getHash(u2, v2, l2, mid))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%d\n", ans);
  }
  return 0;
}