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 int maxn = 3e5 + 10;
char s[maxn];
vector<int> edge[maxn];
int sz[maxn], bel[maxn], fa[maxn], id[maxn], idR[maxn], dep[maxn], tot;
int dfs(int u, int pre) {
  sz[u] = 1, fa[u] = pre, dep[u] = dep[pre] + 1;
  for (auto &v : edge[u])
    if (v != pre) sz[u] += dfs(v, u);
  return sz[u];
}
void dfs2(int u, int num) {
  bel[u] = num, id[u] = ++tot, idR[tot] = u;
  int idx = -1;
  for (auto &v : edge[u])
    if (v != fa[u] && (idx == -1 || sz[idx] < sz[v])) idx = v;
  if (idx == -1) return;
  dfs2(idx, num);
  for (auto &v : edge[u])
    if (v != fa[u] && v != idx) dfs2(v, v);
}
struct SA {
  char s[maxn << 1];
  int sa[maxn << 1], t[maxn << 1], t2[maxn << 1], c[maxn << 1], n;
  void build_sa(int n, int m) {
    int *x = t, *y = t2;
    for (int i = 0; i < m; i++) c[i] = 0;
    for (int i = 0; i < n; i++) c[x[i] = s[i]]++;
    for (int i = 1; i < m; i++) c[i] += c[i - 1];
    for (int i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;
    for (int k = 1; k <= n; k <<= 1) {
      int p = 0;
      for (int i = n - k; i < n; i++) y[p++] = i;
      for (int i = 0; i < n; i++)
        if (sa[i] >= k) y[p++] = sa[i] - k;
      for (int i = 0; i < m; i++) c[i] = 0;
      for (int i = 0; i < n; i++) c[x[y[i]]]++;
      for (int i = 0; i < m; i++) c[i] += c[i - 1];
      for (int i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
      swap(x, y);
      p = 1;
      x[sa[0]] = 0;
      for (int i = 1; i < n; i++)
        x[sa[i]] = y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k]
                       ? p - 1
                       : p++;
      if (p >= n) break;
      m = p;
    }
  }
  int rk[maxn << 1], height[maxn << 1];
  void getHeight() {
    for (int i = 1; i <= n; i++) rk[sa[i]] = i;
    for (int i = 0, k = 0; i < n; i++) {
      if (k) k--;
      int j = sa[rk[i] - 1];
      while (s[i + k] == s[j + k]) k++;
      height[rk[i]] = k;
    }
  }
  int dp[maxn << 1][20];
  void RMQ() {
    for (int i = 1; i <= n; i++) dp[i][0] = height[i];
    for (int j = 1; (1 << j) < maxn << 1; j++)
      for (int i = 1; i + (1 << j) - 1 <= n; i++)
        dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]);
  }
  int query(int l, int r) {
    int k = 0;
    while (1 << (k + 1) <= r - l + 1) k++;
    return min(dp[l][k], dp[r - (1 << k) + 1][k]);
  }
  int _lcp(int x, int y) {
    if (x == y) return n - x + 1;
    x = rk[x - 1], y = rk[y - 1];
    if (x > y) swap(x, y);
    return query(x + 1, y);
  }
  int lcp(int l1, int r1, int l2, int r2) {
    int len = min(abs(r1 - l1) + 1, abs(r2 - l2) + 1);
    if (l1 <= r1 && l2 <= r2)
      return min(len, _lcp(l1, l2));
    else if (l1 <= r1 && l2 > r2)
      return min(len, _lcp(l1, n - l2 + 1));
    else if (l1 > r1 && l2 <= r2)
      return min(len, _lcp(n - l1 + 1, l2));
    else
      return min(len, _lcp(n - l1 + 1, n - l2 + 1));
  }
  void init(string str) {
    n = str.length();
    for (int i = 0; i < n; i++) s[i] = str[i];
    for (int i = 0; i < n; i++) s[i + n] = str[n - i - 1];
    n *= 2;
    build_sa(n + 1, 130);
    getHeight();
    RMQ();
  }
} sa;
struct Seg {
  int l, r;
};
vector<Seg> cal(int u, int v) {
  vector<Seg> res, res2;
  while (bel[u] != bel[v]) {
    if (dep[bel[u]] > dep[bel[v]])
      res.push_back({id[u], id[bel[u]]}), u = fa[bel[u]];
    else
      res2.push_back({id[bel[v]], id[v]}), v = fa[bel[v]];
  }
  res.push_back({id[u], id[v]});
  reverse(res2.begin(), res2.end());
  for (Seg x : res2) res.push_back(x);
  return res;
}
int lcp(vector<Seg> a, vector<Seg> b) {
  int i = 0, j = 0, res = 0;
  while (i < a.size() && j < b.size()) {
    int t = sa.lcp(a[i].l, a[i].r, b[j].l, b[j].r);
    if (!t) return res;
    res += t;
    if (a[i].l <= a[i].r) {
      a[i].l += t;
      if (a[i].l > a[i].r) i++;
    } else {
      a[i].l -= t;
      if (a[i].l < a[i].r) i++;
    }
    if (b[j].l <= b[j].r) {
      b[j].l += t;
      if (b[j].l > b[j].r) j++;
    } else {
      b[j].l -= t;
      if (b[j].l < b[j].r) j++;
    }
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(1, 0);
  dfs2(1, 1);
  string str = "";
  for (int i = 1; i <= n; i++) str += s[idR[i]];
  sa.init(str);
  int q, l1, r1, l2, r2;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
    printf("%d\n", lcp(cal(l1, r1), cal(l2, r2)));
  }
  return 0;
}