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;
long long mod = 1000000007, hp = 1047;
char str[300003];
int n;
vector<int> v[300003];
int pa[300003];
int son[300003], siz[300003];
long long pre[300003], suf[300003];
int dep[300003], top[300003], con[300003];
int dfn[300003], rdfn[300003], DFN;
long long qp[300003];
void dfs1(int x, int p) {
  pa[x] = p;
  dep[x] = dep[p] + 1;
  siz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] == p) continue;
    dfs1(v[x][i], x);
    siz[x] += siz[v[x][i]];
    if (siz[v[x][i]] > siz[son[x]]) son[x] = v[x][i];
  }
}
void dfs2(int x, int p) {
  if (!p) p = x;
  top[x] = p;
  dfn[x] = ++DFN;
  rdfn[dfn[x]] = x;
  if (son[x]) dfs2(son[x], p);
  for (int i = 0; i < v[x].size(); i++)
    if (v[x][i] != pa[x] and v[x][i] != son[x]) dfs2(v[x][i], 0);
}
inline long long ask(int x, int y) {
  if (x > y)
    return (pre[x] - pre[y - 1] * qp[1 + abs(y - x)] % mod + mod) % mod;
  else
    return (suf[x] - suf[y + 1] * qp[1 + abs(y - x)] % mod + mod) % mod;
}
inline vector<pair<int, int> > cut(int x, int y) {
  vector<pair<int, int> > bef, lst;
  while (top[x] != top[y]) {
    if (dep[top[x]] > dep[top[y]]) {
      bef.push_back(make_pair(dfn[x], dfn[top[x]]));
      x = pa[top[x]];
    } else {
      lst.push_back(make_pair(dfn[top[y]], dfn[y]));
      y = pa[top[y]];
    }
  }
  bef.push_back(make_pair(dfn[x], dfn[y]));
  for (int i = lst.size() - 1; i >= 0; i--) bef.push_back(lst[i]);
  return bef;
}
inline int speed(pair<int, int> p) {
  if (p.second >= p.first) return 1;
  return -1;
}
inline int ice(pair<int, int> p) { return abs(p.second - p.first) + 1; }
int asklcp(int x1, int y1, int x2, int y2) {
  int v1 = speed(make_pair(x1, y1)), v2 = speed(make_pair(x2, y2));
  int l = 0, r = min(abs(y2 - x2), abs(y1 - x1));
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ask(x1, x1 + v1 * mid) == ask(x2, x2 + v2 * mid))
      l = mid + 1, ans = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
namespace IOStream {
const int MAXR = 5000000;
char _READ_[MAXR], _PRINT_[MAXR];
char *_READ_POS_, *_PRINT_POS_, *_READ_END_;
inline char readc() {
  if (!_READ_POS_)
    _READ_END_ = (_READ_POS_ = _READ_) + fread(_READ_, 1, MAXR, stdin);
  char c = *(_READ_POS_++);
  if (_READ_POS_ == _READ_END_) _READ_POS_ = 0;
  if (_READ_POS_ > _READ_END_) return 0;
  return c;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  register int flag = 1, c;
  while (((c = readc()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    flag = -1;
  else
    x = c - '0';
  while ((c = readc()) >= '0' && c <= '9') x = x * 10 - '0' + c;
  x *= flag;
}
inline int read(char *s) {
  register int len = 0, c;
  while (isspace(c = readc()) || !c)
    ;
  s[len++] = c;
  while (!isspace(c = readc()) && c) s[len++] = c;
  s[len] = 0;
  return len;
}
template <typename T1, typename... T2>
inline void read(T1 &a, T2 &...x) {
  read(a), read(x...);
}
inline void ioflush() {
  fwrite(_PRINT_, 1, _PRINT_POS_ - _PRINT_, stdout);
  _PRINT_POS_ = 0;
  fflush(stdout);
}
inline void printc(char c) {
  if (!c) return;
  if (!_PRINT_POS_) _PRINT_POS_ = _PRINT_;
  *(_PRINT_POS_++) = c;
  if (_PRINT_POS_ == _PRINT_ + MAXR) ioflush();
}
template <typename T>
inline void print(T x, char c = '\n') {
  if (x < 0) printc('-'), x = -x;
  if (x) {
    static char sta[20];
    register int tp = 0;
    for (; x; x /= 10) sta[tp++] = x % 10 + '0';
    while (tp > 0) printc(sta[--tp]);
  } else
    printc('0');
  printc(c);
}
inline void print(char *s, char c = '\n') {
  for (int i = 0; s[i]; i++) printc(s[i]);
  printc(c);
}
inline void print(const char *s, char c = '\n') {
  for (int i = 0; s[i]; i++) printc(s[i]);
  printc(c);
}
template <typename T1, typename... T2>
inline void print(T1 x, T2... y) {
  print(x, ' '), print(y...);
}
}  // namespace IOStream
using namespace IOStream;
int main() {
  qp[0] = 1;
  for (int i = 1; i < 300003; i++) qp[i] = qp[i - 1] * hp % mod;
  read(n);
  for (int i = 1; i <= n; i++) str[i] = readc();
  for (int i = 1; i < n; i++) {
    int x, y;
    read(x);
    read(y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] * hp + str[rdfn[i]]) % mod;
  for (int i = n; i >= 1; i--) suf[i] = (suf[i + 1] * hp + str[rdfn[i]]) % mod;
  int Q;
  read(Q);
  int cnt = 0;
  while (Q--) {
    cnt++;
    int x1, y1, x2, y2;
    read(x1), read(y1), read(x2), read(y2);
    int lcp = 0;
    vector<pair<int, int> > v1 = cut(x1, y1), v2 = cut(x2, y2);
    int i = 0, j = 0;
    int w1 = 0, w2 = 0;
    while (i < v1.size() and j < v2.size()) {
      int len = min(ice(v1[i]) - w1, ice(v2[j]) - w2);
      int c1 = v1[i].first + speed(v1[i]) * w1,
          d1 = c1 + speed(v1[i]) * (len - 1);
      int c2 = v2[j].first + speed(v2[j]) * w2,
          d2 = c2 + speed(v2[j]) * (len - 1);
      if (ask(c1, d1) != ask(c2, d2)) {
        lcp += asklcp(c1, d1, c2, d2);
        break;
      }
      lcp += len;
      w1 += len, w2 += len;
      if (ice(v1[i]) - w1 == ice(v2[j]) - w2)
        w1 = w2 = 0, i++, j++;
      else if (ice(v1[i]) - w1 < ice(v2[j]) - w2)
        w1 = 0, i++;
      else
        w2 = 0, j++;
    }
    print(lcp, '\n');
  }
  ioflush();
  return 0;
}