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;
struct point {
  int next, to;
} ar[600050];
char s[600050];
long long a[600050], a1[600050], *base, a5[600050];
int head[600050], art, go[600050][20], len[600050], son[600050], dep[600050],
    top[600050], *a2[600050], maxbit[600050], go1[600050][20], tim, a3[600050],
    a4[600050];
inline void read(int&), get(char&), dfs1(int), link(int, int), dfs(int),
    fmod(long long&);
inline long long mult(long long, long long), ask1(int, int, int),
    Fmod(long long);
inline int ask(int, int), lca(int, int), dis(int, int),
    ask2(int, int, int, int);
int main() {
  int n, m;
  read(n);
  for (int i(1); i <= n; ++i) get(s[i]);
  for (int i(1), u, v; i < n; ++i) read(u), read(v), link(u, v);
  base = a5 + n;
  for (int i(base[0] = 1); i <= n; ++i)
    base[i] = mult(base[i - 1], 998244353),
    base[-i] = mult(base[-i + 1], 13199269766116);
  a[1] = a1[1] = s[1], dfs(top[1] = 1), dfs1(1);
  for (int i(1), j, k; i <= n; ++i) {
    if (top[i] ^ i) continue;
    for (j = go[i][0], k = 1; j && k < len[i];
         a2[i][len[i] + k] = j, ++k, j = go[j][0])
      ;
  }
  maxbit[0] = -1;
  for (int i(1); i <= n; ++i) maxbit[i] = maxbit[i >> 1] + 1;
  for (int i, j(1); j < 20; ++j)
    for (i = 1; i + (1 << j) - 1 <= tim; ++i)
      go1[i][j] = dep[go1[i][j - 1]] < dep[go1[i + (1 << j - 1)][j - 1]]
                      ? go1[i][j - 1]
                      : go1[i + (1 << j - 1)][j - 1];
  for (int i(0); 1 << i < 600050; ++i) a4[1 << i] = i;
  for (int i(1); i < 600050; ++i) a4[i] = a4[i] ? a4[i] : a4[i - 1];
  read(m);
  for (int i(1), a, b, c, d; i <= m; ++i) {
    read(a), read(b), read(c), read(d);
    int l(0), mid, r(min(dis(a, b), dis(c, d))), lca1(lca(a, b)),
        lca2(lca(c, d)), opt1, opt2, len1(dep[a] - dep[lca1] + 1),
        len2(dep[c] - dep[lca2] + 1);
    while (mid = l + r + 1 >> 1, l < r)
      opt1 = ask2(a, b, mid, lca1), opt2 = ask2(c, d, mid, lca2),
      ask1(a, opt1, mid <= len1 ? opt1 : lca1) ^
              ask1(c, opt2, mid <= len2 ? opt2 : lca2)
          ? r = mid - 1
          : l = mid;
    printf("%d\n", l);
  }
  return 0;
}
inline int ask2(int x, int y, int k, int lca) {
  if (dep[x] - dep[lca] + 1 >= k) return ask(x, k - 1);
  return ask(y, dep[x] + dep[y] - (dep[lca] << 1) + 1 - k);
}
inline int dis(int x, int y) {
  return dep[x] + dep[y] - (dep[lca(x, y)] << 1) + 1;
}
inline long long Fmod(long long x) { return x + (x >> 63 & 20190816170251); }
inline int lca(int x, int y) {
  x = a3[x], y = a3[y];
  if (x > y) x ^= y ^= x ^= y;
  int len(a4[y - x + 1]);
  x = go1[x][len], y = go1[y - (1 << len) + 1][len];
  return dep[x] < dep[y] ? x : y;
}
inline long long ask1(int x, int y, int lca) {
  return Fmod(mult(Fmod(a1[x] - a1[lca]), base[dep[y] - (dep[lca] << 1)]) +
              Fmod(a[y] - mult(a[go[lca][0]], base[dep[y] - dep[lca] + 1])) -
              20190816170251);
}
inline int ask(int x, int k) {
  if (!k) return x;
  if (k > dep[x]) return 0;
  int b1(maxbit[k]);
  x = go[x][b1], k -= 1 << b1;
  return a2[top[x]][len[x] + k];
}
inline void dfs1(int x) {
  if (top[x] == x) a2[x] = new int[len[x] << 1];
  if (son[x]) top[son[x]] = top[x], dfs1(son[x]);
  for (int i(head[x]), i1; i; i = ar[i].next) {
    if (i1 = ar[i].to, i1 == go[x][0] || i1 == son[x]) continue;
    top[i1] = i1, dfs1(i1);
  }
  a2[top[x]][len[x]] = x;
}
inline void fmod(long long& x) { x += x >> 63 & 20190816170251; }
inline void dfs(int x) {
  go1[a3[x] = ++tim][0] = x;
  for (int i(1); i < 20; ++i) go[x][i] = go[go[x][i - 1]][i - 1];
  for (int i(head[x]), i1; i; i = ar[i].next) {
    if ((i1 = ar[i].to) == go[x][0]) continue;
    dep[i1] = dep[x] + 1, go[i1][0] = x;
    fmod(a[i1] = mult(a[x], 998244353) + s[i1] - 20190816170251);
    fmod(a1[i1] = a1[x] + mult(base[dep[i1]], s[i1]) - 20190816170251);
    if (dfs(i1), len[i1] > len[son[x]]) son[x] = i1;
    go1[++tim][0] = x;
  }
  len[x] = len[son[x]] + 1;
}
inline long long mult(long long x, long long y) {
  long long temp(x * y - (long long)((long double)x * y / 20190816170251) *
                             20190816170251);
  return temp + (temp >> 63 & 20190816170251);
}
inline void link(int u, int v) {
  ar[++art] = {head[u], v}, head[u] = art;
  ar[++art] = {head[v], u}, head[v] = art;
}
inline void get(char& c) {
  while (c = getchar(), c == ' ' || c == '\n' || c == '\r')
    ;
}
inline void read(int& x) {
  x ^= x;
  register char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}