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;
inline int read() {
  int X = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
  return X * w;
}
struct Hash {
  int x, y;
};
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
const Hash BASE = (Hash){2333, 6666};
Hash operator+(Hash x, int y) {
  return (Hash){(x.x + y) % mod1, (x.y + y) % mod2};
}
Hash operator+(Hash x, Hash y) {
  return (Hash){(x.x + y.x) % mod1, (x.y + y.y) % mod2};
}
Hash operator-(Hash x, Hash y) {
  return (Hash){(x.x - y.x + mod1) % mod1, (x.y - y.y + mod2) % mod2};
}
Hash operator*(Hash x, Hash y) {
  return (Hash){(int)(1ll * x.x * y.x % mod1), (int)(1ll * x.y * y.y % mod2)};
}
bool operator==(Hash x, Hash y) { return x.x == y.x && x.y == y.y; }
const int N = 300000 + 10;
int n, m;
char s[N];
Hash pw[N], h1[N], h2[N];
inline Hash gethash(int op, int p, int l) {
  if (op)
    return h1[p + l - 1] - h1[p - 1] * pw[l];
  else
    return h2[p - l + 1] - h2[p + 1] * pw[l];
}
struct edge {
  int v, nxt;
} e[N << 1];
int head[N];
inline void addEdge(int u, int v) {
  static int cnt = 0;
  e[++cnt] = (edge){v, head[u]}, head[u] = cnt;
}
int dep[N], fa[N], sz[N], hson[N], top[N], dfn[N], pos[N], tim = 0;
inline void dfs1(int u, int f) {
  dep[u] = dep[fa[u] = f] + 1, sz[u] = 1;
  for (register int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs1(v, u), sz[u] += sz[v];
    if (sz[v] > sz[hson[u]]) hson[u] = v;
  }
}
inline void dfs2(int u, int anc) {
  top[u] = anc, dfn[u] = ++tim, pos[tim] = u;
  if (hson[u]) dfs2(hson[u], anc);
  for (register int i = head[u]; i; i = e[i].nxt)
    if (e[i].v != fa[u] && e[i].v != hson[u]) dfs2(e[i].v, e[i].v);
}
inline int getlca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = fa[top[u]];
  }
  return dep[u] < dep[v] ? u : v;
}
inline vector<pair<int, int> > divide(int u, int v) {
  int t = getlca(u, v);
  vector<pair<int, int> > x, y;
  while (dep[top[u]] > dep[t])
    x.push_back(make_pair(u, top[u])), u = fa[top[u]];
  x.push_back(make_pair(u, t));
  while (dep[top[v]] > dep[t])
    y.push_back(make_pair(top[v], v)), v = fa[top[v]];
  if (v != t) y.push_back(make_pair(hson[t], v));
  while (y.size()) x.push_back(y.back()), y.pop_back();
  return x;
}
int main() {
  n = read();
  scanf("%s", s + 1);
  for (register int i = 1; i < n; ++i) {
    int u = read(), v = read();
    addEdge(u, v), addEdge(v, u);
  }
  pw[0] = (Hash){1, 1};
  for (register int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * BASE;
  dfs1(1, 0), dfs2(1, 1);
  for (register int i = 1; i <= n; ++i) h1[i] = h1[i - 1] * BASE + s[pos[i]];
  for (register int i = n; i >= 1; --i) h2[i] = h2[i + 1] * BASE + s[pos[i]];
  m = read();
  while (m--) {
    int a = read(), b = read(), c = read(), d = read(), ans = 0;
    vector<pair<int, int> > x = divide(a, b), y = divide(c, d);
    for (register int i = 0, j = 0; i < x.size() && j < y.size();) {
      int x1 = dfn[x[i].first], y1 = dfn[x[i].second];
      int x2 = dfn[y[j].first], y2 = dfn[y[j].second];
      int len = min(abs(x1 - y1), abs(x2 - y2)) + 1;
      Hash hx = gethash(x1 < y1, x1, len), hy = gethash(x2 < y2, x2, len);
      if (hx == hy) {
        if (len == abs(x1 - y1) + 1)
          ++i;
        else
          x[i].first = pos[dfn[x[i].first] + (x1 < y1 ? len : -len)];
        if (len == abs(x2 - y2) + 1)
          ++j;
        else
          y[j].first = pos[dfn[y[j].first] + (x2 < y2 ? len : -len)];
        ans += len;
      } else {
        int L = 1, R = len;
        while (L < R) {
          int mid = (L + R) >> 1;
          hx = gethash(x1 < y1, x1, mid), hy = gethash(x2 < y2, x2, mid);
          if (hx == hy)
            L = mid + 1;
          else
            R = mid;
        }
        ans += L - 1;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}