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 long long INF = 1 << 28;
const long long LINF = 1ll << 61;
inline long long getnum() {
  register long long r = 0;
  register bool ng = 0;
  register char c;
  c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') ng = 1, c = getchar();
  while (c != ' ' && c != '\n') r = r * 10 + c - '0', c = getchar();
  if (ng) r = -r;
  return r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline void putsp() { putchar(' '); }
inline void putendl() { putchar('\n'); }
inline char mygetchar() {
  register char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
int lg2[600111];
struct suffix_array {
  int sa[600111], rk[600111], b[600111], nrk[600111], nsa[600111], lcp[600111];
  void bucketsort(int a[], int n) {
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) b[a[i]]++;
    for (int i = 1; i <= max(256, n); i++) b[i] += b[i - 1];
  }
  int tab[20][600111];
  void construct(char s[], int n) {
    for (int i = 1; i <= n; i++) rk[i] = s[i];
    bucketsort(rk, n);
    for (int i = n; i >= 1; i--) sa[b[rk[i]]--] = i;
    for (int k = 1; k < n; k *= 2) {
      bucketsort(rk, n);
      for (int i = n; i >= 1; i--)
        if (sa[i] > k) nsa[b[rk[sa[i] - k]]--] = sa[i] - k;
      for (int i = n; i >= 1; i--)
        if (sa[i] + k > n) nsa[b[rk[sa[i]]]--] = sa[i];
      nrk[1] = 1;
      for (int i = 2; i <= n; i++)
        nrk[i] = nrk[i - 1] +
                 (make_pair(rk[nsa[i - 1]],
                            nsa[i - 1] + k > n ? -1 : rk[nsa[i - 1] + k]) <
                  make_pair(rk[nsa[i]], nsa[i] + k > n ? -1 : rk[nsa[i] + k]));
      for (int i = 1; i <= n; i++) sa[i] = nsa[i], rk[nsa[i]] = nrk[i];
    }
    for (int i = 1; i <= n; i++) rk[sa[i]] = i;
    int h = 0;
    for (int i = 1; i <= n; i++) {
      if (h > 0) h--;
      if (rk[i] == 1) continue;
      int j = sa[rk[i] - 1];
      while (i + h <= n && j + h <= n && s[i + h] == s[j + h]) h++;
      lcp[rk[i] - 1] = h;
    }
    for (int i = 1; i < n; i++) tab[0][i] = lcp[i];
    for (int j = 1; j < 20; j++)
      for (int i = 1; i + (1 << j) <= n; i++)
        tab[j][i] = min(tab[j - 1][i], tab[j - 1][i + (1 << (j - 1))]);
  }
  int querylcp(int x, int y) {
    if (x == y) return 1000000;
    x = rk[x];
    y = rk[y];
    if (x > y) swap(x, y);
    int t = lg2[y - x];
    return min(tab[t][x], tab[t][y - (1 << t)]);
  }
} usb;
int n, q;
char s[600111];
int head[300111], nxt[600111], to[600111], tot;
int tid[300111], label, son[300111], top[300111], sz[300111], p[300111],
    lv[300111];
void dfs(int x) {
  sz[x] = 1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == p[x]) continue;
    p[to[i]] = x;
    lv[to[i]] = lv[x] + 1;
    dfs(to[i]);
    sz[x] += sz[to[i]];
  }
}
void dfs2(int x) {
  tid[x] = ++label;
  int mx = 0;
  son[x] = -1;
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == p[x]) continue;
    if (sz[to[i]] > mx) {
      mx = sz[to[i]];
      son[x] = to[i];
    }
  }
  if (son[x] != -1) {
    top[son[x]] = top[x];
    dfs2(son[x]);
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] == son[x] || to[i] == p[x]) continue;
    top[to[i]] = to[i];
    dfs2(to[i]);
  }
}
char ts[600111];
pair<int, int> getsegment(int x, int y) {
  if (y >= x)
    return make_pair(x, y);
  else
    return make_pair(2 * n - x + 1, 2 * n - y + 1);
}
void makeroute(int x, int y, vector<pair<int, int> > &ans) {
  vector<pair<int, int> > v1, v2;
  while (true) {
    if (top[x] == top[y]) {
      for (int i = 0; i < v1.size(); i++) ans.push_back(v1[i]);
      ans.push_back(getsegment(tid[x], tid[y]));
      for (int i = int(v2.size()) - 1; i >= 0; i--) ans.push_back(v2[i]);
      return;
    } else if (lv[top[x]] > lv[top[y]]) {
      v1.push_back(getsegment(tid[x], tid[top[x]]));
      x = p[top[x]];
    } else {
      v2.push_back(getsegment(tid[top[y]], tid[y]));
      y = p[top[y]];
    }
  }
}
int main() {
  lg2[1] = 0;
  for (int i = 2; i <= 600055; i++) lg2[i] = lg2[i >> 1] + 1;
  n = getnum();
  for (int i = 1; i <= n; i++) s[i] = mygetchar();
  for (int i = 1; i < n; i++) {
    int x, y;
    x = getnum(), y = getnum();
    nxt[++tot] = head[x];
    head[x] = tot;
    to[tot] = y;
    nxt[++tot] = head[y];
    head[y] = tot;
    to[tot] = x;
  }
  lv[1] = 1;
  p[1] = -1;
  dfs(1);
  top[1] = 1;
  dfs2(1);
  q = getnum();
  for (int i = 1; i <= n; i++) ts[tid[i]] = s[i];
  for (int i = 1; i <= n; i++) ts[n * 2 - i + 1] = ts[i];
  usb.construct(ts, 2 * n);
  while (q--) {
    int xa, ya, xb, yb;
    xa = getnum(), ya = getnum();
    xb = getnum(), yb = getnum();
    vector<pair<int, int> > v1, v2;
    makeroute(xa, ya, v1);
    makeroute(xb, yb, v2);
    int ans = 0, it1 = 0, it2 = 0, len1 = 0, len2 = 0;
    while (it1 < v1.size() && it2 < v2.size()) {
      pair<int, int> &X = v1[it1], &Y = v2[it2];
      int xlen = X.second - X.first - len1, ylen = Y.second - Y.first - len2;
      int tlen = min(xlen, ylen) + 1;
      int curlen = min(usb.querylcp(X.first + len1, Y.first + len2), tlen);
      ans += curlen;
      if (curlen < tlen) break;
      if (curlen > xlen)
        it1++, len1 = 0;
      else
        len1 += curlen;
      if (curlen > ylen)
        it2++, len2 = 0;
      else
        len2 += curlen;
    }
    putnum(ans), putendl();
  }
  return 0;
}