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;
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = getchar();
  }
  x *= f;
}
template <class T>
inline bool Cmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const int mod = 1e9 + 7;
const int base = 37894;
const int maxn = 3e5 + 50;
int n, m;
char s[maxn];
int p[maxn];
int q[maxn];
int dep[maxn];
int len[maxn];
int son[maxn];
int top[maxn];
int head[maxn];
int highbit[maxn];
int H[2][maxn];
int anc[maxn][20];
vector<int> dn[maxn];
vector<int> up[maxn];
struct edge {
  int to, nex;
  edge(int to = 0, int nex = 0) : to(to), nex(nex) {}
};
vector<edge> G;
inline void addedge(int u, int v) {
  G.push_back(edge(v, head[u])), head[u] = G.size() - 1;
  G.push_back(edge(u, head[v])), head[v] = G.size() - 1;
}
inline int sub(int x) { return x < 0 ? x + mod : x; }
long long power(long long x, long long y) {
  long long re = 1;
  while (y) {
    if (y & 1) re = re * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return re;
}
void init(int n) {
  p[0] = q[0] = 1;
  p[1] = base, q[1] = power(base, mod - 2);
  for (int i = 2; i <= n; ++i) {
    p[i] = (long long)p[i - 1] * p[1] % mod;
    q[i] = (long long)q[i - 1] * q[1] % mod;
  }
}
void dfs0(int u) {
  len[u] = 1;
  H[0][u] = ((long long)H[0][anc[u][0]] * base + s[u]) % mod;
  H[1][u] = ((long long)s[u] * p[dep[u]] + H[1][anc[u][0]]) % mod;
  for (int i = 1; i < 20; ++i) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
  }
  for (int i = head[u]; ~i; i = G[i].nex) {
    int v = G[i].to;
    if (v == anc[u][0]) continue;
    dep[v] = dep[u] + 1;
    anc[v][0] = u;
    dfs0(v);
    if (Cmax(len[u], len[v] + 1)) son[u] = v;
  }
}
void dfs1(int u, int chain) {
  top[u] = chain;
  if (son[u]) {
    dfs1(son[u], chain);
  }
  for (int i = head[u]; ~i; i = G[i].nex) {
    int v = G[i].to;
    if (v == son[u] || v == anc[u][0]) continue;
    dfs1(v, v);
  }
}
int jump(int x, int k) {
  if (k > dep[x]) return 0;
  if (k == 0) return x;
  int r = highbit[k];
  x = anc[x][r], k -= (1 << r);
  int y = top[x];
  if (dep[x] - dep[y] >= k) return dn[y][(dep[x] - dep[y]) - k];
  return up[y][k - (dep[x] - dep[y])];
}
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  v = jump(v, dep[v] - dep[u]);
  if (u == v) return u;
  for (int i = 19; ~i; --i) {
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  }
  return anc[u][0];
}
int value(int a, int b, int u, int len) {
  int re = 0;
  int d = min(dep[a] - dep[u] + 1, len);
  int w = jump(a, d);
  re = sub(H[0][a] - (long long)H[0][w] * p[d] % mod);
  len -= d;
  if (len) {
    w = jump(b, dep[b] - dep[u] - len);
    re = (re + (long long)sub(H[1][w] - H[1][u]) * q[dep[u] + 1] % mod * p[d]) %
         mod;
  }
  return re;
}
int main() {
  read(n);
  scanf("%s", s + 1);
  memset(head, -1, sizeof(head));
  for (int i = 1; i < n; ++i) {
    int u, v;
    read(u), read(v);
    addedge(u, v);
  }
  init(n);
  dfs0(1), dfs1(1, 1);
  for (int u = 1; u <= n; ++u)
    if (top[u] == u) {
      for (int i = 0, x = u; i < len[u]; ++i, x = anc[x][0]) up[u].push_back(x);
      for (int i = 0, x = u; i < len[u]; ++i, x = son[x]) dn[u].push_back(x);
    }
  for (int i = 1; i <= n; ++i) {
    for (int j = 19; ~j; --j)
      if (i & (1 << j)) {
        highbit[i] = j;
        break;
      }
  }
  read(m);
  for (int i = 1; i <= m; ++i) {
    int a, b, c, d;
    read(a), read(b), read(c), read(d);
    int u = lca(a, b), v = lca(c, d);
    int l = 0,
        r = 1 + min(dep[a] + dep[b] - (dep[u] << 1),
                    dep[c] + dep[d] - (dep[v] << 1)),
        an = -1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (value(a, b, u, mid) == value(c, d, v, mid))
        l = mid + 1, an = mid;
      else
        r = mid - 1;
    }
    printf("%d\n", an);
  }
  return 0;
}