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 = 6e5 + 10, LG = 20, inf = 1e9;
vector<int> v[maxn];
int h[maxn], SZ[maxn], tp[maxn], st[maxn], C, n;
int rnk[LG][maxn], lcp[LG][maxn], pos[maxn];
pair<pair<int, int>, int> arr[maxn];
string str;
char s[maxn];
void dfssz(int u, int H = 1, int par = 0) {
  SZ[u] = 1;
  h[u] = H;
  for (int y : v[u])
    if (y != par) dfssz(y, H + 1, u), SZ[u] += SZ[y];
}
void prep(int u, bool bl = 1) {
  sort(v[u].begin(), v[u].end(), [](int a, int b) { return SZ[a] < SZ[b]; });
  st[u] = C++;
  str += s[u - 1];
  if (bl)
    tp[u] = u;
  else
    tp[u] = tp[v[u].back()];
  if (int((v[u]).size()) >= 2) prep(v[u][int((v[u]).size()) - 2], 0);
  for (int i = 0; i < int((v[u]).size()) - 2; i++) prep(v[u][i], 1);
}
vector<pair<int, int> > LCA(int a, int b) {
  vector<pair<int, int> > ans1, ans2;
  while (tp[a] != tp[b]) {
    if (h[tp[a]] > h[tp[b]]) {
      ans1.push_back({C + C - 1 - st[a], C + C - 1 - st[tp[a]]});
      a = v[tp[a]].back();
    } else {
      ans2.push_back({st[tp[b]], st[b]});
      b = v[tp[b]].back();
    }
  }
  if (h[a] < h[b]) {
    ans1.push_back({st[a], st[b]});
  } else {
    ans1.push_back({C + C - 1 - st[a], C + C - 1 - st[b]});
  }
  for (int i = int((ans2).size()) - 1; i >= 0; i--) ans1.push_back(ans2[i]);
  return ans1;
}
int LCP(int a, int b) {
  if (a == b) return inf;
  if (a > b) swap(a, b);
  int id = 31 - __builtin_clz(b - a);
  return min(lcp[id][a], lcp[id][b - (1 << id)]);
}
int _LCP(int a, int b) {
  int ans = 0;
  for (int i = LG - 1; i >= 0; i--) {
    if (a + (1 << i) <= int((str).size()) &&
        b + (1 << i) <= int((str).size()) && rnk[i][a] == rnk[i][b])
      ans += (1 << i), a += (1 << i), b += (1 << i);
  }
  return ans;
}
int main() {
  scanf("%d%s", &n, s);
  for (int i = 2; i <= n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dfssz(1);
  v[1].push_back(0), SZ[0] = inf;
  prep(1);
  for (int i = n - 1; i >= 0; i--) {
    str += str[i];
  }
  for (int i = 0; i < int((str).size()); i++) {
    rnk[0][i] = str[i] - 'a';
  }
  for (int i = 1; i < LG; i++) {
    for (int j = 0; j < int((str).size()); j++)
      arr[j] = {{rnk[i - 1][j], j + (1 << (i - 1)) >= int((str).size())
                                    ? -1
                                    : rnk[i - 1][j + (1 << (i - 1))]},
                j};
    sort(arr, arr + int((str).size()));
    for (int j = 1; j < int((str).size()); j++)
      rnk[i][arr[j].second] =
          rnk[i][arr[j - 1].second] + (arr[j - 1].first != arr[j].first);
  }
  for (int i = 0; i < int((str).size()) - 1; i++) {
    lcp[0][i] = _LCP(arr[i].second, arr[i + 1].second);
  }
  for (int i = 1; i < LG; i++) {
    for (int j = 0; j < int((str).size()); j++) {
      lcp[i][j] = lcp[i - 1][j];
      if (j + (1 << (i - 1)) < int((str).size()))
        lcp[i][j] = min(lcp[i][j], lcp[i - 1][j + (1 << (i - 1))]);
    }
  }
  for (int i = 0; i < int((str).size()); i++) {
    pos[arr[i].second] = i;
  }
  int m;
  scanf("%d", &m);
  vector<pair<int, int> > v1, v2;
  while (m--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    v1 = LCA(a, b);
    v2 = LCA(c, d);
    int ans = 0;
    reverse(v1.begin(), v1.end());
    reverse(v2.begin(), v2.end());
    while (!v1.empty() && !v2.empty()) {
      int m = min(v1.back().second - v1.back().first + 1,
                  v2.back().second - v2.back().first + 1);
      int num = min(LCP(pos[v1.back().first], pos[v2.back().first]), m);
      ans += num;
      if (num < m) break;
      if (num == v1.back().second - v1.back().first + 1)
        v1.pop_back();
      else
        v1[int((v1).size()) - 1].first += num;
      if (num == v2.back().second - v2.back().first + 1)
        v2.pop_back();
      else
        v2[int((v2).size()) - 1].first += num;
    }
    printf("%d\n", ans);
  }
}