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;
void read(int &res) {
  char u;
  do {
    u = getchar();
  } while (u < '0' || '9' < u);
  res = u - '0';
  while (1) {
    u = getchar();
    if ('0' <= u && u <= '9')
      res = res * 10 + u - '0';
    else
      break;
  }
}
void write(int res) {
  char c[11];
  int m = 0;
  do {
    c[++m] = res % 10 + '0';
    res /= 10;
  } while (res);
  while (m) putchar(c[m--]);
}
int n, Q, deg[300005];
vector<int> g[300005];
char s[300005], a[2 * 300005];
int cl[300005], pre[300005], depth[300005], x[300005];
int cnt[300005], child[300005];
int xhlt[300005], pos[300005], head[300005], dhlt[300005];
int sa[2 * 300005], key[2 * 300005], mark[2 * 300005];
pair<pair<int, int>, int> p[2 * 300005];
int lcp[2 * 300005], rk[2 * 300005];
int f[2 * 300005][21];
pair<int, int> p1[300005], p2[300005];
int sl1, sl2;
pair<int, int> pa[50], pb[50];
int sla, slb;
void ExtractHLT(int r) {
  int L = 1, R = 0;
  x[++R] = 1;
  cl[r] = 1;
  pre[r] = depth[r] = 0;
  while (L <= R) {
    int u = x[L++];
    for (int i = 0; i < deg[u]; ++i) {
      int v = g[u][i];
      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];
    cnt[u] = 1;
    int slmax = 0;
    for (int j = 0; j < deg[u]; ++j) {
      int v = g[u][j];
      if (pre[v] != u) continue;
      cnt[u] += cnt[v];
      if (slmax < cnt[v]) {
        slmax = cnt[v];
        child[u] = v;
      }
    }
    if (slmax < cnt[u] / 2) child[u] = 0;
  }
  int m = 0;
  for (int i = 1; i <= n; ++i) {
    int u = x[i];
    if (u == r || child[pre[u]] != u) {
      xhlt[++m] = u;
      pos[u] = m;
      head[u] = u;
      int v = u;
      while (child[v]) {
        v = child[v];
        xhlt[++m] = v;
        pos[v] = m;
        head[v] = u;
      }
    }
  }
  dhlt[r] = 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 (pre[v] == u && child[u] != v) dhlt[v] = dhlt[head[u]] + 1;
    }
  }
}
void SA() {
  for (int i = 1; i <= 2 * n; ++i)
    p[i] = pair<pair<int, int>, int>(pair<int, int>(a[i], 0), i);
  sort(p + 1, p + 2 * n + 1);
  for (int i = 1; i <= 2 * n; ++i) sa[i] = p[i].second;
  mark[1] = 1;
  for (int i = 2; i <= 2 * n; ++i) mark[i] = (p[i].first != p[i - 1].first);
  for (int k = 1; k <= 2 * n; k *= 2) {
    int val = 0;
    for (int i = 1; i <= 2 * n; ++i) {
      val += mark[i];
      key[sa[i]] = val;
    }
    if (val == 2 * 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);
    for (int i = 1; i <= 2 * n; ++i) sa[i] = p[i].second;
    mark[1] = 1;
    for (int i = 2; i <= 2 * n; ++i) mark[i] = (p[i].first != p[i - 1].first);
  }
}
void LCP() {
  for (int i = 1; i <= 2 * n; ++i) rk[sa[i]] = i;
  lcp[1] = 0;
  int q = 0;
  for (int i = 1; i <= 2 * n; ++i)
    if (rk[i] > 1) {
      int j = sa[rk[i] - 1];
      while (a[i + q] == a[j + q]) ++q;
      lcp[rk[i]] = q;
      --q;
      if (q < 0) q = 0;
    }
}
void RMQ() {
  int m = log2(2 * n) + 1;
  for (int i = 1; i <= 2 * n; ++i)
    for (int k = 0; k <= m; ++k) f[i][k] = 1e9;
  for (int i = 1; i <= 2 * n; ++i) f[i][0] = lcp[i];
  for (int k = 1; k <= m; ++k)
    for (int i = 1; i + (1 << k) - 1 <= 2 * n; ++i)
      f[i][k] = min(f[i][k - 1], f[i + (1 << (k - 1))][k - 1]);
}
void tao(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);
}
int calc(int u, int v) {
  if (u > v) swap(u, v);
  if (u == v) return 2 * n - sa[u] + 1;
  ++u;
  int k = log2(v - u + 1);
  int q = min(f[u][k], f[v - (1 << k) + 1][k]);
  return q;
}
void tinh(int a, int b, int c, int d) {
  sl1 = sl2 = 0;
  tao(a, b);
  for (int i = 1; i <= sla; ++i) p1[++sl1] = pa[i];
  for (int i = slb; i >= 1; --i) p1[++sl1] = pb[i];
  tao(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 = min(min(p1[u].second, p2[v].second),
                calc(rk[p1[u].first], rk[p2[v].first]));
    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) break;
    if (v > sl2) break;
  }
  write(ds);
  putchar('\n');
}
int main() {
  cin.tie(0);
  cout.tie(0);
  read(n);
  gets(s + 1);
  for (int i = 1; i <= n - 1; ++i) {
    int u, v;
    read(u);
    read(v);
    deg[u]++;
    g[u].push_back(v);
    deg[v]++;
    g[v].push_back(u);
  }
  ExtractHLT(1);
  for (int i = 1; i <= n; ++i) {
    a[i] = s[xhlt[i]];
    a[2 * n - i + 1] = a[i];
  }
  SA();
  LCP();
  RMQ();
  read(Q);
  while (Q--) {
    int a, b, c, d;
    read(a);
    read(b);
    read(c);
    read(d);
    tinh(a, b, c, d);
  }
}