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;
template <int maxn>
struct SuffixArray {
  char s[maxn];
  int sa[maxn], c[maxn], t[maxn], t2[maxn], n;
  void build_sa(int m) {
    int i, *x = t, *y = t2;
    for (i = 0; i < m; i++) c[i] = 0;
    for (i = 0; i < n; i++) c[x[i] = s[i]]++;
    for (i = 1; i < m; i++) c[i] += c[i - 1];
    for (i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;
    for (int k = 1; k < n; k <<= 1) {
      int p = 0;
      for (i = n - 1; i >= n - k; i--) y[p++] = i;
      for (i = 0; i < n; i++)
        if (sa[i] >= k) y[p++] = sa[i] - k;
      for (i = 0; i < m; i++) c[i] = 0;
      for (i = 0; i < n; i++) c[x[y[i]]]++;
      for (i = 1; i < m; i++) c[i] += c[i - 1];
      for (i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
      p = 1;
      swap(x, y);
      x[sa[0]] = 0;
      for (i = 1; i < n; i++)
        x[sa[i]] = y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]
                       ? p - 1
                       : p++;
      if (p >= n) break;
      m = p;
    }
  }
  int h[maxn], rk[maxn];
  void get_height() {
    int i, j, k = 0;
    for (i = 0; i < n; i++) rk[sa[i]] = i;
    for (i = 0; i < n; i++) {
      if (k) k--;
      if (!rk[i]) {
        continue;
      }
      j = sa[rk[i] - 1];
      while (s[i + k] == s[j + k]) k++;
      h[rk[i]] = k;
    }
  }
  int d[maxn][20], lg[maxn];
  void init_lcp() {
    for (int i = 0; i < n; i++) {
      d[i][0] = h[i];
    }
    lg[0] = -1;
    for (int i = 1; i <= n; i++) {
      lg[i] = lg[i >> 1] + 1;
    }
    for (int j = 1; (1 << j) <= n; j++) {
      for (int i = 0; i + (1 << j) - 1 < n; i++) {
        d[i][j] = min(d[i][j - 1], d[i + (1 << (j - 1))][j - 1]);
      }
    }
  }
  inline int lcp(int l, int r) {
    l = rk[l];
    r = rk[r];
    if (l == r) return n - sa[l];
    if (l > r) swap(l, r);
    l++;
    int k = lg[r - l + 1];
    return min(d[l][k], d[r - (1 << k) + 1][k]);
  }
};
const int maxn = 300010;
SuffixArray<maxn + maxn> sa;
int head[maxn], en[maxn << 1], nxt[maxn << 1], tot;
inline void add(int u, int v) {
  en[++tot] = v;
  nxt[tot] = head[u];
  head[u] = tot;
}
char cost[maxn];
int fa[maxn], size[maxn], son[maxn], dep[maxn];
void dfs(int u) {
  size[u] = 1;
  for (int k = head[u]; k; k = nxt[k]) {
    int v = en[k];
    if (v == fa[u]) {
      continue;
    }
    fa[v] = u;
    dep[v] = dep[u] + 1;
    dfs(v);
    size[u] += size[v];
    if (size[son[u]] < size[v]) {
      son[u] = v;
    }
  }
}
int top[maxn], pos[maxn], dfs_clock;
int ls[maxn], le[maxn];
void build_tree(int u, int pre) {
  top[u] = pre;
  ls[u] = pos[u] = dfs_clock++;
  if (son[u]) {
    build_tree(son[u], pre);
  }
  for (int k = head[u]; k; k = nxt[k]) {
    int v = en[k];
    if (v == fa[u] || v == son[u]) {
      continue;
    }
    build_tree(v, v);
  }
  le[u] = dfs_clock - 1;
}
pair<int, int> lseg[maxn], rseg[maxn];
int lseg_s, rseg_s;
int n;
inline bool in(int f, int x) { return ls[f] <= ls[x] && le[x] <= le[f]; }
inline int segment_get(int a, int b, pair<int, int>* res) {
  static pair<int, int> up[maxn], down[maxn];
  int up_s = 0, down_s = 0;
  while (!in(top[a], b)) {
    up[up_s++] = make_pair((n + n - (pos[a]) - 1), (n + n - (pos[top[a]]) - 1));
    a = fa[top[a]];
  }
  while (!in(top[b], a)) {
    down[down_s++] = make_pair(pos[top[b]], pos[b]);
    b = fa[top[b]];
  }
  if (in(a, b)) {
    down[down_s++] = make_pair(pos[a], pos[b]);
  } else {
    up[up_s++] = make_pair((n + n - (pos[a]) - 1), (n + n - (pos[b]) - 1));
  }
  int m = 0;
  for (int i = 0; i < up_s; i++) {
    res[m++] = up[i];
  }
  for (int i = down_s - 1; i >= 0; i--) {
    res[m++] = down[i];
  }
  return m;
}
int main() {
  scanf("%d%s", &n, cost + 1);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  dfs(1);
  build_tree(1, 1);
  for (int i = 1; i <= n; i++) {
    sa.s[pos[i]] = sa.s[(n + n - (pos[i]) - 1)] = cost[i];
  }
  sa.n = n + n;
  sa.build_sa(256);
  sa.get_height();
  sa.init_lcp();
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    lseg_s = segment_get(a, b, lseg);
    rseg_s = segment_get(c, d, rseg);
    int i = 0, j = 0, ans = 0;
    while (i < lseg_s && j < rseg_s) {
      assert(lseg[i].first <= lseg[i].second);
      assert(rseg[j].first <= rseg[j].second);
      int tmp = sa.lcp(lseg[i].first, rseg[j].first);
      tmp = min(tmp, lseg[i].second - lseg[i].first + 1);
      tmp = min(tmp, rseg[j].second - rseg[j].first + 1);
      ans += tmp;
      lseg[i].first += tmp;
      rseg[j].first += tmp;
      bool ok = false;
      if (lseg[i].first > lseg[i].second) {
        i++;
        ok = true;
      }
      if (rseg[j].first > rseg[j].second) {
        j++;
        ok = true;
      }
      if (!ok) {
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}