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 = 300005, p = 31, mod = 998244353;
int base[1 << 18 | 5], MaxDep[Maxn], son[Maxn], hbit[Maxn], top[Maxn],
    len[Maxn], dep[Maxn], h[Maxn], w[Maxn];
int f[Maxn][20], g1[Maxn][20], g2[Maxn][20];
vector<int> U[Maxn], D[Maxn];
struct node {
  int to, next;
} e[2 * Maxn];
void AddEdge(int x, int y) {
  static int cnt;
  e[++cnt] = (node){y, h[x]};
  h[x] = cnt;
}
inline int Getint() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
inline char Getchar() {
  char ch = getchar();
  while (!isalpha(ch)) ch = getchar();
  return ch;
}
void dfs(int x, int fa) {
  f[x][0] = fa;
  dep[x] = dep[fa] + 1;
  g1[x][0] = w[x];
  g2[x][0] = w[x];
  for (int i = 1; i < 20; i++) {
    f[x][i] = f[f[x][i - 1]][i - 1];
    g1[x][i] =
        (1ll * g1[x][i - 1] * base[1 << (i - 1)] + g1[f[x][i - 1]][i - 1]) %
        mod;
    g2[x][i] =
        (g2[x][i - 1] + 1ll * g2[f[x][i - 1]][i - 1] * base[1 << (i - 1)]) %
        mod;
  }
  MaxDep[x] = dep[x];
  for (int p = h[x]; p; p = e[p].next) {
    int y = e[p].to;
    if (y == fa) continue;
    dfs(y, x);
    if (MaxDep[y] > MaxDep[son[x]]) son[x] = y;
    MaxDep[x] = max(MaxDep[x], MaxDep[y]);
  }
}
void dfs2(int x, int fa) {
  len[x] = MaxDep[x] - dep[top[x]] + 1;
  if (!son[x]) return;
  top[son[x]] = top[x];
  dfs2(son[x], x);
  for (int p = h[x]; p; p = e[p].next) {
    int y = e[p].to;
    if (y != fa && y != son[x]) top[y] = y, dfs2(y, x);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; ~i; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 19; ~i; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
int Getkfa(int x, int k) {
  if (!k) return x;
  x = f[x][hbit[k]], k ^= 1 << hbit[k];
  if (!k) return x;
  if (k == dep[x] - dep[top[x]]) return top[x];
  if (k > dep[x] - dep[top[x]]) return U[top[x]][k - dep[x] + dep[top[x]] - 1];
  return D[top[x]][dep[x] - dep[top[x]] - k - 1];
}
int Move(int s, int t, int o) {
  if (dep[s] < dep[t]) {
    if (o > dep[t] - dep[s]) return -1;
    return Getkfa(t, dep[t] - dep[s] - o);
  }
  if (o > dep[s] - dep[t]) return -1;
  return Getkfa(s, o);
}
int GetHash(int s, int t) {
  bool flag = false;
  if (dep[s] < dep[t]) swap(s, t), flag = 1;
  int hash = 0, len = 0;
  for (int i = 19; ~i; i--)
    if (dep[f[s][i]] >= dep[t]) {
      if (flag) {
        hash = (1ll * g2[s][i] * base[len] + hash) % mod;
        len += (1 << i);
      } else {
        hash = (1ll * hash * base[1 << i] + g1[s][i]) % mod;
      }
      s = f[s][i];
    }
  if (flag)
    hash = (1ll * g2[s][0] * base[len] + hash) % mod;
  else
    hash = (1ll * hash * base[1] + g1[s][0]) % mod;
  return hash;
}
int GetHash1(int s, int lca, int t, int len) {
  if (dep[s] + dep[t] - 2 * dep[lca] + 1 < len) return -1;
  if (len <= dep[s] - dep[lca] + 1) return GetHash(s, Getkfa(s, len - 1));
  int R = len - dep[s] + dep[lca] - 1;
  int l = GetHash(s, lca);
  int r = GetHash(Getkfa(t, dep[t] - dep[lca] - 1),
                  Getkfa(t, dep[t] - dep[lca] - R));
  int ret = (1ll * l * base[R] + r) % mod;
  return ret;
}
int GetHash2(int s, int t, int o) {
  if (abs(dep[s] - dep[t]) + 1 < (1 << o)) return -1;
  if (dep[s] >= dep[t]) return g1[s][o];
  int pos = Getkfa(t, dep[t] - dep[s] - (1 << o) + 1);
  return g2[pos][o];
}
int main() {
  for (int i = base[0] = 1; i < (1 << 18 | 5); i++)
    base[i] = 1ll * base[i - 1] * p % mod;
  int n = Getint();
  for (int i = 1; i <= n; i++) w[i] = Getchar() - 'a' + 1;
  for (int i = 1; i < n; i++) {
    int x = Getint(), y = Getint();
    AddEdge(x, y);
    AddEdge(y, x);
  }
  dfs(1, 0);
  top[1] = 1;
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    if (i != top[i]) continue;
    int l, x;
    l = 0, x = i;
    while (l < len[i] && x) x = f[x][0], U[i].push_back(x), ++l;
    l = 0, x = i;
    while (l < len[i]) x = son[x], D[i].push_back(x), ++l;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 19; j >= 0; --j)
      if (i >> j & 1) {
        hbit[i] = j;
        break;
      }
  int m = Getint();
  while (m--) {
    int x1 = Getint(), y1 = Getint(), lca1 = lca(x1, y1);
    int x2 = Getint(), y2 = Getint(), lca2 = lca(x2, y2);
    int ans = 0;
    if (dep[x1] - dep[lca1] > dep[x2] - dep[lca2])
      swap(x1, x2), swap(y1, y2), swap(lca1, lca2);
    do {
      if (GetHash1(x1, lca1, y1, dep[x1] - dep[lca1] + 1) !=
          GetHash1(x2, lca2, y2, dep[x1] - dep[lca1] + 1)) {
        auto check = [&](int i) {
          int l = GetHash2(x1, lca1, i);
          int r = GetHash2(x2, lca2, i);
          if (l == r && l != -1) {
            ans += 1 << i;
            x1 = Move(x1, lca1, 1 << i);
            x2 = Move(x2, lca2, 1 << i);
          }
        };
        for (int i = 19; ~i; i--) check(i);
      } else if (GetHash1(x1, lca1, y1, dep[x2] - dep[lca2] + 1) !=
                 (GetHash1(x2, lca2, y2, dep[x2] - dep[lca2] + 1))) {
        ans = dep[x1] - dep[lca1] + 1;
        x2 = Move(x2, lca2, dep[x1] - dep[lca1] + 1);
        x1 = Move(lca1, y1, 1);
        if (x1 == -1) break;
        auto check = [&](int i) {
          if (x1 == -1 || x2 == -1) return;
          int l = GetHash2(x1, y1, i);
          int r = GetHash2(x2, lca2, i);
          if (l == r && l != -1) {
            ans += 1 << i;
            x1 = Move(x1, y1, 1 << i);
            x2 = Move(x2, lca2, 1 << i);
          }
        };
        for (int i = 19; ~i; i--) check(i);
        if (~x1 && ~x2 && w[x1] == w[x2]) ans++;
      } else {
        ans = dep[x2] - dep[lca2] + 1;
        x1 = Move(lca1, y1, 1 + (dep[x2] - dep[lca2]) - (dep[x1] - dep[lca1]));
        x2 = Move(lca2, y2, 1);
        if (x1 == -1 || x2 == -1) break;
        auto check = [&](int i) {
          if (x1 == -1 || x2 == -1) return;
          int l = GetHash2(x1, y1, i);
          int r = GetHash2(x2, y2, i);
          if (l == r && l != -1) {
            ans += 1 << i;
            x1 = Move(x1, y1, 1 << i);
            x2 = Move(x2, y2, 1 << i);
          }
        };
        for (int i = 19; ~i; i--) check(i);
        if (~x1 && ~x2 && w[x1] == w[x2]) ans++;
      }
    } while (0);
    cout << ans << "\n";
  }
  return 0;
}