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 = 300500;
const int MAXK = 19;
int par[MAXK][MAXN];
int tin[MAXN], tout[MAXN];
bool used[MAXN];
int h[MAXN];
const int MOD = 1000000009;
const int BASE = 1248217;
int hs[MAXK][MAXN];
int rhs[MAXK][MAXN];
int pows[MAXN];
vector<vector<int> > g;
int n, m;
char buf[MAXN];
void dfs(int x, int pr) {
  static int timer = 0;
  used[x] = true;
  h[x] = h[pr] + 1;
  tin[x] = timer++;
  par[0][x] = pr;
  hs[0][x] = buf[x];
  rhs[0][x] = buf[pr];
  for (auto son : g[x]) {
    if (son != pr) {
      dfs(son, x);
    }
  }
  tout[x] = timer++;
}
void propagate() {
  for (int lvl = 1; lvl < MAXK; ++lvl) {
    for (int i = 1; i <= n; ++i) {
      par[lvl][i] = par[lvl - 1][par[lvl - 1][i]];
    }
    for (int i = 1; i <= n; ++i) {
      hs[lvl][i] = (1ll * hs[lvl - 1][i] * pows[1 << (lvl - 1)] +
                    hs[lvl - 1][par[lvl - 1][i]]) %
                   MOD;
      rhs[lvl][i] =
          (1ll * rhs[lvl - 1][par[lvl - 1][i]] * pows[1 << (lvl - 1)] +
           rhs[lvl - 1][i]) %
          MOD;
    }
  }
}
void precalc() {
  pows[0] = 1;
  for (int i = 1; i < MAXN; ++i) {
    pows[i] = 1ll * pows[i - 1] * BASE % MOD;
  }
}
inline bool is_par(int pr, int son) {
  return (tin[pr] <= tin[son] && tout[pr] >= tout[son]);
}
int lca(int u, int v) {
  if (is_par(u, v)) {
    return u;
  }
  if (is_par(v, u)) {
    return v;
  }
  int curv = u;
  for (int i = MAXK - 1; i >= 0; --i) {
    int nextv = par[i][curv];
    if (nextv != 0 && !is_par(nextv, v)) {
      curv = nextv;
    }
  }
  return par[0][curv];
}
int up_vertex(int u, int height) {
  for (int i = MAXK - 1; i >= 0; --i) {
    if (height >= (1 << i)) {
      u = par[i][u];
      height ^= (1 << i);
    }
  }
  return u;
}
int main() {
  precalc();
  scanf("%d", &n);
  g.clear();
  g.resize(n + 1);
  buf[0] = 0;
  h[0] = -1;
  scanf(" %s", buf + 1);
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 0);
  propagate();
  scanf("%d", &m);
  for (int qid = 0; qid < m; ++qid) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int u1 = lca(a, b), u2 = lca(c, d);
    int len1 = h[a] - h[u1], len2 = h[c] - h[u2];
    int clen = min(h[a] + h[b] - 2 * h[u1], h[c] + h[d] - 2 * h[u2]);
    {
      if (len1 > clen) {
        len1 = clen;
        b = u1 = up_vertex(a, len1);
      } else {
        b = up_vertex(b, h[b] - h[u1] - (clen - len1));
      }
      if (len2 > clen) {
        len2 = clen;
        d = u2 = up_vertex(c, len2);
      } else {
        d = up_vertex(d, h[d] - h[u2] - (clen - len2));
      }
    }
    if (len1 > len2) {
      swap(a, c);
      swap(b, d);
      swap(u1, u2);
      swap(len1, len2);
    }
    int svlen1 = len1, svlen2 = len2;
    int aa = a, bb = b, cc = c, dd = d;
    int cur_ans = 0;
    {
      bool ok = true;
      int i = MAXK - 1;
      int rlen = len1;
      for (; i >= 0 && ok; --i) {
        if (rlen >= (1 << i)) {
          if (hs[i][a] == hs[i][c]) {
            cur_ans += (1 << i);
            rlen -= (1 << i);
            a = par[i][a], c = par[i][c];
          } else {
            ok = false;
          }
        }
      }
      if (!ok) {
        while (i >= 0) {
          if (hs[i][a] == hs[i][c]) {
            cur_ans += (1 << i);
            a = par[i][a], c = par[i][c];
          }
          --i;
        }
      }
    }
    if (cur_ans == len1) {
      if (len1 != len2) {
        int idealh = len2 - len1;
        int fv = a = up_vertex(b, h[b] - h[u1] - idealh), sv = c;
        vector<int> vertices;
        vertices.reserve(19);
        for (int i = 0, curv = fv; i < MAXK; ++i) {
          if (idealh & (1 << i)) {
            vertices.push_back(curv);
            curv = par[i][curv];
          }
        }
        bool ok = true;
        int i = MAXK - 1;
        for (; i >= 0 && ok; --i) {
          if (idealh >= (1 << i)) {
            if (rhs[i][vertices.back()] == hs[i][sv]) {
              vertices.pop_back();
              cur_ans += (1 << i);
              idealh -= (1 << i);
              sv = par[i][sv];
            } else {
              ok = false;
            }
          }
        }
        if (!ok) {
          fv = vertices.back();
          while (i >= 0) {
            int nextv = par[i][fv];
            if (rhs[i][nextv] != hs[i][sv]) {
              fv = nextv;
            } else {
              cur_ans += (1 << i);
              sv = par[i][sv];
            }
            --i;
          }
        }
      }
      if (cur_ans == len2) {
        int rlen = clen - len2;
        int fv = b, sv = d;
        vector<int> v1, v2;
        v1.reserve(19), v2.reserve(19);
        for (int i = 0; i < MAXK; ++i) {
          if (rlen & (1 << i)) {
            v1.push_back(fv);
            v2.push_back(sv);
            fv = par[i][fv];
            sv = par[i][sv];
          }
        }
        int i = MAXK - 1;
        bool ok = true;
        for (; i >= 0 && ok; --i) {
          if (rlen >= (1 << i)) {
            if (rhs[i][v1.back()] == rhs[i][v2.back()]) {
              v1.pop_back();
              v2.pop_back();
              cur_ans += (1 << i);
              rlen -= (1 << i);
            } else {
              ok = false;
            }
          }
        }
        if (!ok) {
          fv = v1.back(), sv = v2.back();
          while (i >= 0) {
            int nfv = par[i][fv], nsv = par[i][sv];
            if (rhs[i][nfv] != rhs[i][nsv]) {
              fv = nfv, sv = nsv;
            } else {
              cur_ans += (1 << i);
            }
            --i;
          }
        }
      }
    }
    if (cur_ans > svlen1) {
      aa = up_vertex(bb, clen - cur_ans);
    } else {
      aa = up_vertex(aa, cur_ans);
    }
    if (cur_ans > svlen2) {
      cc = up_vertex(dd, clen - cur_ans);
    } else {
      cc = up_vertex(cc, cur_ans);
    }
    cur_ans += buf[aa] == buf[cc];
    printf("%d\n", cur_ans);
  }
  return 0;
}