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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline", "no-stack-protector", "unroll-loops")
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void gi(I &x) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = (x << 1) + (x << 3) + (c & 15);
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
inline void read(char *s) {
  for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c < 'a' || c > 'z';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
  for (int i = 1; c >= 'a' && c <= 'z';
       i++, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                            (iS == iT ? EOF : *iS++))
                          : *iS++))
    s[i] = c;
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::gi;
using io ::print;
using io ::putc;
using io ::read;
const int N = 300005;
int Head[N], Next[N << 1], Adj[N << 1], tot = 0;
void addedge(int u, int v) {
  Next[++tot] = Head[u], Head[u] = tot, Adj[tot] = v;
  Next[++tot] = Head[v], Head[v] = tot, Adj[tot] = u;
}
int deep[N], fa[N], size[N], top[N], son[N];
char s[N];
void dfs(int x) {
  size[x] = 1;
  for (int e = Head[x]; e; e = Next[e])
    if (Adj[e] != fa[x]) {
      fa[Adj[e]] = x;
      deep[Adj[e]] = deep[x] + 1;
      dfs(Adj[e]);
      size[x] += size[Adj[e]];
      son[x] = (size[son[x]] > size[Adj[e]] ? son[x] : Adj[e]);
    }
}
int dfn[N], to[N], Time = 0;
void dfs2(int x, int tp) {
  top[x] = tp, dfn[x] = ++Time, to[Time] = x;
  if (!son[x]) return;
  dfs2(son[x], tp);
  for (int e = Head[x]; e; e = Next[e])
    if (Adj[e] != fa[x] && Adj[e] != son[x]) dfs2(Adj[e], Adj[e]);
}
inline int LCA(int u, int v) {
  for (; top[u] != top[v];
       deep[top[u]] < deep[top[v]] ? v = fa[top[v]] : u = fa[top[u]])
    ;
  return deep[u] < deep[v] ? u : v;
}
vector<pair<int, int> > path(int u, int v) {
  int lca = LCA(u, v);
  vector<pair<int, int> > ans;
  while (top[u] != top[lca])
    ans.push_back(make_pair(u, top[u])), u = fa[top[u]];
  ans.push_back(make_pair(u, lca));
  vector<pair<int, int> > tmp;
  while (top[v] != top[lca])
    tmp.push_back(make_pair(top[v], v)), v = fa[top[v]];
  if (v != lca) tmp.push_back(make_pair(son[lca], v));
  for (int i = tmp.size() - 1; i >= 0; i--) ans.push_back(tmp[i]);
  return ans;
}
const int base = 2333, Mod = 1e9 + 7;
int h1[N], h2[N], b[N];
inline int getHash(int o, int l, int d) {
  if (!o)
    return (1ll * h1[l + d - 1] - 1ll * h1[l - 1] * b[d] % Mod + Mod) % Mod;
  return (1ll * h2[l - d + 1] - 1ll * h2[l + 1] * b[d] % Mod + Mod) % Mod;
}
int main() {
  int n;
  gi(n);
  read(s);
  for (int i = 1; i < n; i++) {
    int u, v;
    gi(u), gi(v);
    addedge(u, v);
  }
  dfs(1), dfs2(1, 1);
  b[0] = 1;
  for (int i = 1; i <= n; i++) b[i] = 1ll * b[i - 1] * base % Mod;
  for (int i = 1; i <= n; i++)
    h1[i] = (1ll * h1[i - 1] * base + s[to[i]] - 'a') % Mod;
  for (int i = n; i >= 1; i--)
    h2[i] = (1ll * h2[i + 1] * base + s[to[i]] - 'a') % Mod;
  int q;
  gi(q);
  while (q--) {
    int a, b, c, d;
    gi(a), gi(b), gi(c), gi(d);
    vector<pair<int, int> > l1 = path(a, b);
    vector<pair<int, int> > l2 = path(c, d);
    int ans = 0;
    for (int i = 0, j = 0; i < l1.size() && j < l2.size();) {
      int df1 = dfn[l1[i].first], df2 = dfn[l1[i].second];
      int dg1 = dfn[l2[j].first], dg2 = dfn[l2[j].second];
      bool of = (df1 > df2), og = (dg1 > dg2);
      int lf = abs(df1 - df2) + 1, lg = abs(dg1 - dg2) + 1;
      int len = min(lf, lg);
      if (getHash(of, df1, len) == getHash(og, dg1, len)) {
        if (len == lf)
          ++i;
        else
          l1[i].first = to[df1 + (of ? -len : len)];
        if (len == lg)
          ++j;
        else
          l2[j].first = to[dg1 + (og ? -len : len)];
        ans += len;
      } else {
        int l = 1, r = len, pos = 0;
        while (l <= r) {
          int mid = (l + r) >> 1;
          if (getHash(of, df1, mid) == getHash(og, dg1, mid))
            pos = mid, l = mid + 1;
          else
            r = mid - 1;
        }
        ans += pos;
        break;
      }
    }
    print(ans), putc('\n');
  }
  return 0;
}