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;
int sa[2 * 300006], lcp[2 * 300006];
char T[2 * 300006];
int n;
pair<pair<int, int>, int> p[2 * 300006];
bool mark[2 * 300006];
int key[2 * 300006];
char a[300006];
int deg[300006];
vector<int> g[300006];
int read() {
  char u;
  int v = 0;
  while (1) {
    u = getchar();
    if (u >= '0' && u <= '9') {
      v = u - '0';
      break;
    }
  }
  while (1) {
    u = getchar();
    if (u >= '0' && u <= '9')
      v = v * 10 + u - '0';
    else
      break;
  }
  return v;
}
void doc() {
  n = read();
  scanf("\n");
  gets(a + 1);
  scanf("\n");
  int u, v;
  for (int i = 1; i < n; i++) {
    u = read();
    v = read();
    deg[u]++;
    deg[v]++;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
int x[300006], cl[300006], cnt[300006], child[300006], pre[300006],
    slx = 0, head[300006], xhlt[300006], dhlt[300006], depth[300006],
    pos[300006];
void HLT() {
  int L = 1, R = 0;
  x[++R] = 1;
  cl[1] = 1;
  depth[1] = pre[1] = 0;
  while (L <= R) {
    int u = x[L++];
    for (int j = 0; j < deg[u]; j++) {
      int v = g[u][j];
      if (cl[v] == 0) {
        cl[v] = 1;
        pre[v] = u;
        depth[v] = depth[u] + 1;
        x[++R] = v;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    int u = x[i], slmax = 0;
    cnt[u] = 1;
    for (int j = 0; j < deg[u]; j++) {
      int v = g[u][j];
      if (pre[v] == u) {
        cnt[u] += cnt[v];
        if (cnt[v] > slmax) slmax = cnt[v], child[u] = v;
      }
    }
    if (slmax * 2 < cnt[u]) child[u] = 0;
  }
  int m = 0;
  for (int i = 1; i <= n; i++) {
    int u = x[i];
    if (child[pre[u]] != u || u == 1) {
      head[u] = u;
      xhlt[++m] = u;
      pos[u] = m;
      int v = u;
      while (child[v] != 0) {
        v = child[v];
        xhlt[++m] = v;
        pos[v] = m;
        head[v] = u;
      }
    }
  }
  dhlt[1] = 0;
  for (int i = 1; i <= n; i++) {
    int u = x[i];
    for (int j = 0; j < deg[u]; j++) {
      int v = g[u][j];
      if (v != child[u] && pre[v] == u) dhlt[head[v]] = dhlt[head[u]] + 1;
    }
  }
  for (int i = 1; i <= n; i++) T[i] = a[xhlt[i]];
  for (int i = 1; i <= n; i++) T[i + n] = a[xhlt[n - i + 1]];
}
void initsuff() {
  for (int i = 1; i <= 2 * n; ++i)
    p[i] = pair<pair<int, int>, int>(pair<int, int>(T[i], 0), i);
  sort(p + 1, p + 2 * n + 1);
  mark[1] = true;
  for (int i = 2; i <= 2 * n; ++i) mark[i] = (p[i].first != p[i - 1].first);
  for (int i = 1; i <= 2 * n; ++i) sa[i] = p[i].second;
}
void SA() {
  for (int k = 1; k * 2 < 2 * n; k *= 2) {
    int val = 0;
    for (int i = 1; i <= 2 * n; ++i) {
      if (mark[i]) ++val;
      key[sa[i]] = val;
    }
    if (val == n) break;
    for (int i = 1; i <= 2 * n; ++i) {
      int t = (i + k <= 2 * n) ? key[i + k] : 0;
      p[i] = pair<pair<int, int>, int>(pair<int, int>(key[i], t), i);
    }
    sort(p + 1, p + 2 * n + 1);
    mark[1] = true;
    for (int i = 2; i <= 2 * n; ++i) mark[i] = (p[i].first != p[i - 1].first);
    for (int i = 1; i <= 2 * n; ++i) sa[i] = p[i].second;
  }
}
int rk[2 * 300006];
void LCP() {
  for (int i = 1; i <= 2 * n; ++i) rk[sa[i]] = i;
  int q = 0;
  lcp[1] = 0;
  for (int i = 1; i <= 2 * n; ++i)
    if (rk[i] > 1) {
      int j = sa[rk[i] - 1];
      while (T[i + q] == T[j + q]) ++q;
      lcp[rk[i]] = q;
      q--;
      if (q < 0) q = 0;
    }
}
int f[2 * 300006][20];
pair<int, int> pa[100], pb[100];
int sla, slb;
void handling() {
  for (int i = 1; i <= 2 * n; ++i) f[i][0] = lcp[i];
  int k = log2(2 * n) + 1;
  for (int u = 1; u <= k; ++u)
    for (int i = 1; (i + (1 << u) - 1) <= 2 * n; i++)
      f[i][u] = min(f[i][u - 1], f[i + (1 << (u - 1))][u - 1]);
}
int tinh(int u, int v) {
  if (u > v) return 0;
  int k = (log2(v - u + 1));
  return min(f[u][k], f[v - (1 << k) + 1][k]);
}
int callcp(int u, int v, int l1, int l2) {
  if (u == v) return min(2 * n - u + 1, min(l1, l2));
  u = rk[u];
  v = rk[v];
  if (u > v) swap(u, v);
  int ds = tinh(u + 1, v);
  ds = min(ds, min(l1, l2));
  return ds;
}
void findpath(int u, int v) {
  sla = slb = 0;
  while (dhlt[head[u]] > dhlt[head[v]]) {
    pa[++sla] = pair<int, int>(2 * n - pos[u] + 1, pos[u] - pos[head[u]] + 1);
    u = pre[head[u]];
  }
  while (dhlt[head[v]] > dhlt[head[u]]) {
    pb[++slb] = pair<int, int>(pos[head[v]], pos[v] - pos[head[v]] + 1);
    v = pre[head[v]];
  }
  while (head[u] != head[v]) {
    pa[++sla] = pair<int, int>(2 * n - pos[u] + 1, pos[u] - pos[head[u]] + 1);
    u = pre[head[u]];
    pb[++slb] = pair<int, int>(pos[head[v]], pos[v] - pos[head[v]] + 1);
    v = pre[head[v]];
  }
  if (depth[u] > depth[v])
    pa[++sla] = pair<int, int>(2 * n - pos[u] + 1, pos[u] - pos[v] + 1);
  else
    pb[++slb] = pair<int, int>(pos[u], pos[v] - pos[u] + 1);
}
pair<int, int> p1[100], p2[100];
int sl1 = 0, sl2 = 0;
int query(int a, int b, int c, int d) {
  findpath(a, b);
  sl1 = 0, sl2 = 0;
  for (int i = 1; i <= sla; i++) p1[++sl1] = pa[i];
  for (int i = slb; i >= 1; i--) p1[++sl1] = pb[i];
  findpath(c, d);
  for (int i = 1; i <= sla; i++) p2[++sl2] = pa[i];
  for (int i = slb; i >= 1; i--) p2[++sl2] = pb[i];
  int u = 1, v = 1;
  int ds = 0;
  while (1) {
    int k = callcp(p1[u].first, p2[v].first, p1[u].second, p2[v].second);
    ds += k;
    if (k < p1[u].second && k < p2[v].second) break;
    if (k == p1[u].second && k < p2[v].second) {
      ++u;
      p2[v].first += k;
      p2[v].second -= k;
    } else if (k < p1[u].second && k == p2[v].second) {
      ++v;
      p1[u].first += k;
      p1[u].second -= k;
    } else if (k == p1[u].second && k == p2[v].second) {
      ++u;
      ++v;
    }
    if (u > sl1 || v > sl2) break;
  }
  return ds;
}
int tt;
int main() {
  doc();
  HLT();
  initsuff();
  SA();
  LCP();
  {
    handling();
    tt = read();
    int u, v, r, z;
    while (tt) {
      tt--;
      u = read();
      v = read();
      r = read();
      z = read();
      printf("%d\n", query(u, v, r, z));
    }
  }
}