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 + 10;
const int INF = 2e9;
const double eps = 1e-6;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int base = 131;
int n, m;
int dep[MAXN], p[MAXN][21], fa[MAXN];
int pw[MAXN], ip[MAXN];
char s[MAXN];
vector<int> G[MAXN];
template <typename T>
inline bool read(T &a) {
  a = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    a = a * 10 + (c ^ 48);
    c = getchar();
  }
  return a *= f, true;
}
template <typename A, typename... B>
inline bool read(A &x, B &...y) {
  return read(x) && read(y...);
}
int qpow(int x, int b) {
  int res = 1;
  for (; b; b >>= 1, x = 1ll * x * x % mod)
    if (b & 1) res = 1ll * res * x % mod;
  return res;
}
void DFS(int x, int f) {
  fa[x] = p[x][0] = f, dep[x] = dep[f] + 1;
  for (int i = 1; i <= 20; ++i) p[x][i] = p[p[x][i - 1]][i - 1];
  for (auto to : G[x])
    if (to ^ f) DFS(to, x);
}
namespace Hash {
int up[MAXN], dn[MAXN];
void DFS(int x) {
  up[x] = (1ll * up[fa[x]] * base % mod + s[x]) % mod;
  dn[x] = (dn[fa[x]] + 1ll * qpow(base, dep[x] - 1) * s[x] % mod) % mod;
  for (auto to : G[x])
    if (to != fa[x]) DFS(to);
}
int UP(int x, int y) {
  if (dep[x] < dep[y] || !y) return 0;
  int len = dep[x] - dep[y] + 1;
  return (up[x] - 1ll * up[fa[y]] * pw[len] % mod + mod) % mod;
}
int DN(int x, int y) {
  int res = (dn[y] - dn[fa[x]] + mod) % mod;
  res = 1ll * res * ip[dep[x] - 1] % mod;
  return res;
}
void build() {
  DFS(1);
  pw[0] = ip[0] = 1, pw[1] = base, ip[1] = qpow((base), mod - 2);
  for (int i = 1; i <= n; ++i) {
    pw[i] = 1ll * pw[i - 1] * pw[1] % mod;
    ip[i] = 1ll * ip[i - 1] * ip[1] % mod;
  }
}
}  // namespace Hash
namespace kth {
int top[MAXN];
int len[MAXN], son[MAXN], hb[MAXN];
int topbit[MAXN];
vector<int> up[MAXN], dn[MAXN];
void DFS1(int x) {
  len[x] = dep[x];
  for (auto to : G[x]) {
    if (to == fa[x]) continue;
    DFS1(to);
    if (len[to] > len[x]) son[x] = to, len[x] = len[to];
  }
}
void DFS2(int x, int tp) {
  top[x] = tp;
  if (x == tp) {
    for (int i = 0, v = x; i <= len[x] - dep[x]; ++i)
      up[x].emplace_back(v), v = fa[v];
    for (int i = 0, v = x; i <= len[x] - dep[x]; ++i)
      dn[x].emplace_back(v), v = son[v];
  }
  if (son[x]) DFS2(son[x], tp);
  for (auto to : G[x]) {
    if (to == son[x] || to == fa[x]) continue;
    DFS2(to, to);
  }
}
void build() {
  for (int i = 1; i <= n; ++i) hb[i] = hb[i >> 1] + 1;
  DFS1(1);
  DFS2(1, 1);
}
int qk(int x, int k) {
  if (k < 0 || k > dep[x]) return 0;
  if (!k) return x;
  int bit = hb[k];
  k -= (1 << (bit - 1));
  x = p[x][bit - 1];
  k -= dep[x] - dep[top[x]];
  x = top[x];
  if (k >= 0)
    return up[x][k];
  else
    return dn[x][-k];
}
}  // namespace kth
using Hash ::DN;
using Hash ::UP;
using kth ::qk;
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; ~i; --i)
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  if (x == y) return x;
  for (int i = 20; ~i; --i)
    if (p[x][i] != p[y][i]) x = p[x][i], y = p[y][i];
  return p[x][0];
}
int way(int a, int b, int lca, int len) {
  if (dep[a] - dep[lca] + 1 >= len) return UP(a, qk(a, len - 1));
  int res = UP(a, qk(a, dep[a] - dep[lca] - 1)), anc;
  len -= dep[a] - dep[lca];
  anc = qk(b, (dep[b] - dep[lca] + 1) - len);
  res = (res + 1ll * pw[dep[a] - dep[lca]] * DN(lca, anc)) % mod;
  return res;
}
int calc() {
  int a, b, c, d;
  read(a), read(b), read(c), read(d);
  if (s[a] != s[c]) return 0;
  int l1 = LCA(a, b), l2 = LCA(c, d), L = 1, R, mid;
  R = min(dep[a] + dep[b] - dep[l1] * 2 + 1, dep[c] + dep[d] - dep[l2] * 2 + 1);
  while (L < R) {
    mid = (L + R + 1) >> 1;
    if (way(a, b, l1, mid) == way(c, d, l2, mid))
      L = mid;
    else
      R = mid - 1;
  }
  return L;
}
signed main() {
  read(n);
  scanf("%s", s + 1);
  for (int i = 1, x, y; i < n; ++i) {
    read(x), read(y);
    G[x].emplace_back(y), G[y].emplace_back(x);
  }
  DFS(1, 0);
  Hash ::build(), kth ::build();
  read(m);
  while (m--) printf("%d\n", calc());
  return 0;
}