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;
constexpr int lgn = 22, maxn = 3e5 + 4, inf = 0x3f3f3f3f;
int logger[2 * maxn] = {};
struct SA {
  vector<int> sa, rk, ht;
  vector<int> st[lgn];
  void init(const string& s) {
    sa.resize(s.size());
    rk.resize(s.size());
    ht.resize(s.size());
    const int lgs = ceil(log2(s.size())) + 1;
    vector<tuple<int, int, int> > t(s.size());
    vector<int> trk(s.size());
    for (int i = 0; i < s.size(); ++i) t[i] = tuple<int, int, int>(s[i], 0, i);
    for (int k = 0; k < lgs; ++k) {
      sort(t.begin(), t.end());
      const int stp = (1 << k);
      for (int i = 0, scnt = -1; i < t.size(); ++i) {
        if (i == 0 || get<0>(t[i]) != get<0>(t[i - 1]) ||
            get<1>(t[i]) != get<1>(t[i - 1]))
          trk[i] = ++scnt;
        else
          trk[i] = scnt;
        sa[i] = get<2>(t[i]);
        rk[get<2>(t[i])] = i;
      }
      for (int i = 0; i < trk.size(); ++i) get<0>(t[i]) = trk[i];
      for (auto& [v1, v2, id] : t)
        v2 = ((id + stp < s.size()) ? trk[rk[id + stp]] : -1);
    }
    ht[0] = 0;
    for (int i = 0; i < s.size(); ++i) rk[sa[i]] = i;
    for (int i = 0, k = 0; i < s.size(); ++i) {
      if (rk[i] == 0) continue;
      if (k) --k;
      while (i + k < s.size() && sa[rk[i] - 1] + k < s.size() &&
             s[i + k] == s[sa[rk[i] - 1] + k])
        ++k;
      ht[rk[i]] = k;
    }
  }
  void prepare() {
    st[0].resize(ht.size());
    for (int i = 0; i < ht.size(); ++i) st[0][i] = ht[i];
    const int lgk = ceil(log2(ht.size()));
    for (int k = 1; k < lgk; ++k) {
      st[k].resize(ht.size(), inf);
      for (int i = 0; i < ht.size(); ++i) {
        if (i + (1 << (k - 1)) < ht.size())
          st[k][i] = min(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]);
        else
          st[k][i] = st[k - 1][i];
      }
    }
  }
  int getlcp(int x, int y) {
    if (x == y) return inf;
    x = rk[x];
    y = rk[y];
    if (x > y) swap(x, y);
    ++x;
    const int len = logger[y - x + 1];
    return min(st[len][x], st[len][y - (1 << len) + 1]);
  }
} sa;
inline void prepare() {
  for (int i = 2; i < 2 * maxn; ++i) logger[i] = logger[i / 2] + 1;
}
struct Node {
  int par, dep, dfn, hson, top, sz;
  char c;
} nodes[maxn];
vector<int> verts[maxn];
void predfs(int u) {
  nodes[u].sz = 1;
  for (int v : verts[u]) {
    if (v == nodes[u].par) continue;
    nodes[v].dep = nodes[u].dep + 1;
    nodes[v].par = u;
    predfs(v);
    nodes[u].sz += nodes[v].sz;
    if (nodes[v].sz > nodes[nodes[u].hson].sz) nodes[u].hson = v;
  }
}
int clkc = 0;
void dfs(int u) {
  nodes[u].dfn = clkc++;
  if (nodes[u].hson) {
    nodes[nodes[u].hson].top = nodes[u].top;
    dfs(nodes[u].hson);
  }
  for (int v : verts[u]) {
    if (v == nodes[u].par || v == nodes[u].hson) continue;
    nodes[v].top = v;
    dfs(v);
  }
}
int N;
inline void gtop(int x, int y, vector<pair<int, int> >& v) {
  vector<pair<int, int> > vt;
  while (nodes[x].top != nodes[y].top) {
    if (nodes[nodes[x].top].dep > nodes[nodes[y].top].dep) {
      v.push_back(pair<int, int>((2 * N - (nodes[x].dfn) - 1),
                                 (2 * N - (nodes[nodes[x].top].dfn) - 1)));
      x = nodes[nodes[x].top].par;
    } else {
      vt.push_back(pair<int, int>(nodes[nodes[y].top].dfn, nodes[y].dfn));
      y = nodes[nodes[y].top].par;
    }
  }
  if (nodes[x].dep > nodes[y].dep)
    v.push_back(pair<int, int>((2 * N - (nodes[x].dfn) - 1),
                               (2 * N - (nodes[y].dfn) - 1)));
  else
    vt.push_back(pair<int, int>(nodes[x].dfn, nodes[y].dfn));
  v.insert(v.end(), vt.rbegin(), vt.rend());
}
inline int match(const vector<pair<int, int> >& a,
                 const vector<pair<int, int> >& b) {
  int p = 0, q = 0, cp = 0, cq = 0;
  int sum = 0;
  for (; p < a.size() && q < b.size();) {
    const int l = min({sa.getlcp(a[p].first + cp, b[q].first + cq),
                       ((a[p]).second - (a[p]).first + 1) - cp,
                       ((b[q]).second - (b[q]).first + 1) - cq});
    cp += l;
    cq += l;
    sum += l;
    if (cp == ((a[p]).second - (a[p]).first + 1))
      ++p, cp = 0;
    else if (cq == ((b[q]).second - (b[q]).first + 1))
      ++q, cq = 0;
    else
      break;
  }
  return sum;
}
inline void pack() {
  string str;
  str.resize(N);
  nodes[1].dep = nodes[1].top = 1;
  predfs(1);
  dfs(1);
  for (int i = 1; i <= N; ++i) str[nodes[i].dfn] = nodes[i].c;
  str += string(str.rbegin(), str.rend());
  sa.init(str);
  sa.prepare();
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> nodes[i].c;
  for (int i = 1; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    verts[a].push_back(b);
    verts[b].push_back(a);
  }
  prepare();
  pack();
  int M;
  cin >> M;
  for (int i = 0; i < M; ++i) {
    int xi, yi, xii, yii;
    cin >> xi >> yi >> xii >> yii;
    vector<pair<int, int> > a, b;
    gtop(xi, yi, a);
    gtop(xii, yii, b);
    cout << match(a, b) << '\n';
  }
  return 0;
}