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>
const int N = 300005;
namespace sam {
const int N = 1200005;
int fail[N], max[N], nxt[N][27], pos[N];
int st[21][N], idx = 1, lst = 1;
void append(char ch, int id) {
  int p = lst, np = lst = ++idx;
  max[np] = max[p] + 1, pos[id] = np;
  for (; p && !nxt[p][ch]; p = fail[p]) nxt[p][ch] = np;
  if (!p)
    fail[np] = 1;
  else {
    int q = nxt[p][ch];
    if (max[p] + 1 == max[q])
      fail[np] = q;
    else {
      int nq = ++idx;
      max[nq] = max[p] + 1;
      std::memcpy(nxt[nq], nxt[q], 27 << 2);
      fail[nq] = fail[q], fail[q] = fail[np] = nq;
      for (; nxt[p][ch] == q; p = fail[p]) nxt[p][ch] = nq;
    }
  }
}
int head[N], _nxt[N], clk, dfn[N];
inline void link(int x, int y) { _nxt[y] = head[x], head[x] = y; }
void dfs(int x, int f = 0) {
  st[0][clk] = f, dfn[x] = ++clk;
  for (int i = head[x]; i; i = _nxt[i]) dfs(i, x);
}
inline int _max(int x, int y) { return dfn[x] < dfn[y] ? x : y; }
void init() {
  for (int i = 1; i <= 20; ++i)
    for (int j = 1; j + (1 << i) - 1 < idx; ++j)
      st[i][j] = _max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
}
int lca(int x, int y) {
  if (x == y) return x;
  if (dfn[x] > dfn[y]) std::swap(x, y);
  int k = 31 - __builtin_clz(dfn[y] - dfn[x]);
  return _max(st[k][dfn[x]], st[k][dfn[y] - (1 << k)]);
}
int lcp(int x, int y) { return max[lca(pos[x], pos[y])]; }
void build(const std::string& s) {
  for (int i = s.size() - 1; ~i; --i) append(s[i] - 'a', i + 1);
  for (int i = 2; i <= idx; ++i) link(fail[i], i);
  dfs(1), init();
}
}  // namespace sam
int n, idx;
std::string s, t;
int dfn[N], size[N], son[N], top[N], dep[N], f[N], head[N], tot;
struct edge {
  int to, nxt;
} e[N << 1];
void link(int x, int y) {
  e[++tot] = (edge){y, head[x]}, head[x] = tot;
  e[++tot] = (edge){x, head[y]}, head[y] = tot;
}
int dfs0(int x) {
  dep[x] = dep[f[x]] + 1;
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != f[x]) {
      f[e[i].to] = x, size[x] += dfs0(e[i].to);
      if (size[e[i].to] > size[son[x]]) son[x] = e[i].to;
    }
  return ++size[x];
}
void dfs1(int x) {
  t[idx] = s[x - 1], dfn[x] = ++idx;
  if (son[x]) top[son[x]] = top[x], dfs1(son[x]);
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != son[x] && e[i].to != f[x])
      top[e[i].to] = e[i].to, dfs1(e[i].to);
}
void get_path(int x, int y, std::vector<std::pair<int, int>>& L) {
  std::vector<std::pair<int, int>> R;
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]]) {
      L.emplace_back(2 * (n + 1) - dfn[x], 2 * (n + 1) - dfn[top[x]]);
      x = f[top[x]];
    } else {
      R.emplace_back(dfn[top[y]], dfn[y]);
      y = f[top[y]];
    }
  }
  if (dep[x] < dep[y]) {
    R.emplace_back(dfn[x], dfn[y]);
  } else {
    L.emplace_back(2 * (n + 1) - dfn[x], 2 * (n + 1) - dfn[y]);
  }
  for (int i = R.size() - 1; ~i; --i) L.emplace_back(R[i]);
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> s, t.resize(n);
  for (int i = 1, x, y; i < n; ++i) std::cin >> x >> y, link(x, y);
  dfs0(1), top[1] = 1, dfs1(1);
  t = t + '#' + std::string(t.rbegin(), t.rend());
  sam::build(t);
  int m;
  std::cin >> m;
  while (m--) {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    std::vector<std::pair<int, int>> L, R;
    get_path(a, b, L), get_path(c, d, R);
    int Lp = 0, Rp = 0, Ls = 0, Rs = 0, LCP = 0;
    while (Lp < L.size() && Rp < R.size()) {
      int l = sam::lcp(L[Lp].first + Ls, R[Rp].first + Rs);
      l = std::min(l, std::min(L[Lp].second - L[Lp].first - Ls + 1,
                               R[Rp].second - R[Rp].first - Rs + 1));
      Ls += l, Rs += l, LCP += l;
      bool k = 0;
      if (Ls == L[Lp].second - L[Lp].first + 1) ++Lp, Ls = 0, k = 1;
      if (Rs == R[Rp].second - R[Rp].first + 1) ++Rp, Rs = 0, k = 1;
      if (!k) break;
    }
    std::cout << LCP << '\n';
  }
  return 0;
}