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;
namespace TYC {
const int N = 300000 + 5, M = 19;
const int seed = 23333, p = 1e9 + 7;
int n, Pow[N], invP[N], A[N], B[N];
char S[N];
vector<int> E[N];
namespace Tree {
int top[N], len[N], son[N], Pool[N << 2], *up[N], *down[N], dep[N], fa[M][N],
    log2[N];
void dfs(const int u, const int f) {
  dep[u] = dep[fa[0][u] = f] + 1;
  for (int i = 1; i < M && fa[i - 1][u]; i++)
    fa[i][u] = fa[i - 1][fa[i - 1][u]];
  int c = S[u] - 'a' + 1;
  A[u] = ((long long)A[f] * seed + c) % p;
  B[u] = ((long long)c * Pow[dep[f]] + B[f]) % p;
  for (int v : E[u])
    if (v != f) {
      dfs(v, u);
      if (len[v] + 1 > len[u]) len[u] = len[son[u] = v];
    }
  len[u]++;
}
void dfs(const int u, const int f, const int ance) {
  top[u] = ance;
  if (son[u]) dfs(son[u], u, ance);
  for (int v : E[u])
    if (v != f && v != son[u]) dfs(v, u, v);
}
void init() {
  dfs(1, 0);
  dfs(1, 0, 1);
  for (int i = 1, t = 0; i <= n; log2[i++] = t)
    if ((1 << (t + 1)) == i) ++t;
  int *tmp = Pool;
  for (int i = 1; i <= n; i++)
    if (i == top[i]) {
      down[i] = tmp, tmp += len[i];
      for (int j = 0, k = i; j <= len[i]; j++) down[i][j] = k, k = son[k];
      up[i] = tmp, tmp += len[i];
      for (int j = 0, k = i; j <= len[i] && k; j++) up[i][j] = k, k = fa[0][k];
    }
}
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int d = dep[u] - dep[v], i = 0; d; d >>= 1, i++)
    if (d & 1) u = fa[i][u];
  if (u == v) return u;
  for (int i = M - 1; ~i; i--)
    if (fa[i][u] != fa[i][v]) u = fa[i][u], v = fa[i][v];
  return fa[0][u];
}
inline int getance(int x, int k) {
  if (!k) return x;
  x = fa[log2[k]][x];
  k -= 1 << log2[k];
  if (!k)
    return x;
  else if (dep[x] - dep[top[x]] == k)
    return top[x];
  else if (dep[x] - dep[top[x]] >= k)
    return down[top[x]][dep[x] - dep[top[x]] - k];
  else
    return up[top[x]][k - dep[x] + dep[top[x]]];
}
}  // namespace Tree
using Tree::dep;
using Tree::getance;
using Tree::LCA;
inline int qpow(int x, int tim) {
  int ans = 1;
  for (; tim; tim >>= 1, x = (long long)x * x % p)
    if (tim & 1) ans = (long long)ans * x % p;
  return ans;
}
inline int extractA(int x, int len) {
  int y = getance(x, len);
  return (A[x] - (long long)A[y] * Pow[len] % p + p) % p;
}
inline int extractB(int x, const int y) {
  return (long long)(B[x] - B[y] + p) % p * invP[dep[y]] % p;
}
inline int extractB(const int a, const int b, const int len) {
  return extractB(getance(a, dep[a] - dep[b] - len), b);
}
void work() {
  scanf("%d%s", &n, S + 1);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    E[u].push_back(v);
    E[v].push_back(u);
  }
  Pow[0] = 1;
  for (int i = 1; i <= n; i++) {
    Pow[i] = (long long)Pow[i - 1] * seed % p;
    invP[i] = qpow(Pow[i], p - 2);
  }
  Tree::init();
  int m, a, b, lca1, c, d, lca2, l, r, mid, ans;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    lca1 = LCA(a, b);
    lca2 = LCA(c, d);
    if (dep[a] - dep[lca1] > dep[c] - dep[lca2]) {
      swap(a, c);
      swap(b, d);
      swap(lca1, lca2);
    }
    int l1 = dep[a] - dep[lca1] + 1, l2 = dep[c] - dep[lca2] + 1;
    int mxl =
        min(dep[a] + dep[b] - dep[lca1] * 2, dep[c] + dep[d] - dep[lca2] * 2) +
        1;
    ans = 0;
    if (mxl >= l1 && extractA(a, l1) == extractA(c, l1)) {
      c = getance(c, l1);
      l2 -= l1;
      mxl -= l1;
      if (mxl >= l2 && extractB(b, lca1, l2) == extractA(c, l2)) {
        l = 0, r = mxl - l2;
        lca1 = getance(b, dep[b] - dep[lca1] - l2);
        while (l <= r) {
          mid = (l + r) >> 1;
          if (extractB(b, lca1, mid) == extractB(d, lca2, mid))
            ans = mid, l = mid + 1;
          else
            r = mid - 1;
        }
        ans += l2;
      } else {
        l = 0, r = min(mxl, l2);
        while (l <= r) {
          mid = (l + r) >> 1;
          if (extractB(b, lca1, mid) == extractA(c, mid))
            ans = mid, l = mid + 1;
          else
            r = mid - 1;
        }
      }
      ans += l1;
    } else {
      l = 0, r = min(l1, mxl);
      while (l <= r) {
        mid = (l + r) >> 1;
        if (extractA(a, mid) == extractA(c, mid))
          ans = mid, l = mid + 1;
        else
          r = mid - 1;
      }
    }
    printf("%d\n", ans);
  }
}
}  // namespace TYC
int main() {
  TYC::work();
  return 0;
}