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>
const size_t IBUFSIZ = 1 << 24;
char ibuf[IBUFSIZ | 1];
const char *const ep = ibuf + IBUFSIZ;
const char *sp = ep - 1;
int _;
constexpr int BS = 521, P = 1073741789;
struct edge {
  int next, to;
} e[300010 << 1];
typedef int arr[300010];
int ei, cnt;
char c[300010];
arr head, siz, hson, top, dep, fa, dfn, seg, pre, suf, bs;
std::vector<std::pair<int, int>>::iterator it, jt;
template <const int P = ::P>
constexpr int fix(const int &x) {
  return x + ((x >> 31) & P);
}
void dfs1(const int &f) {
  dep[f] = dep[fa[f]] + 1;
  siz[f] = 1;
  for (int i = head[f]; i; i = e[i].next) {
    const int t = e[i].to;
    if (!siz[t]) {
      fa[t] = f;
      dfs1(t);
      if (siz[t] > siz[hson[f]]) hson[f] = t;
      siz[f] += siz[t];
    }
  }
}
void dfs2(const int &f) {
  dfn[f] = ++cnt;
  seg[cnt] = f;
  if (hson[f]) {
    top[hson[f]] = top[f];
    dfs2(hson[f]);
    for (int i = head[f]; i; i = e[i].next) {
      const int t = e[i].to;
      if (t != fa[f] && t != hson[f]) {
        top[t] = t;
        dfs2(t);
      }
    }
  }
}
void getpath(int x, int y, std::vector<std::pair<int, int>> &ans) {
  static std::vector<std::pair<int, int>> tmp;
  ans.clear();
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) {
      tmp.push_back(std::make_pair(top[y], y));
      y = fa[top[y]];
    } else {
      ans.push_back(std::make_pair(x, top[x]));
      x = fa[top[x]];
    }
  }
  ans.push_back(std::make_pair(x, y));
  while (!tmp.empty()) {
    ans.push_back(tmp.back());
    tmp.pop_back();
  }
}
inline int hash(const bool &r, const int &p, const int &l) {
  return r ? fix(suf[p - l + 1] - 1ll * suf[p + 1] * bs[l] % P)
           : fix(pre[p + l - 1] - 1ll * pre[p - 1] * bs[l] % P);
}
int main() {
  bs[0] = 1;
  const int n = ({
    while ((__builtin_expect(++sp == ep, false) &&
                (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
            *sp) < 48) {
    }
    _ = *sp ^ 48;
    while ((__builtin_expect(++sp == ep, false) &&
                (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
            *sp) >= 48)
      _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
    _;
  });
  for (int i = 1; i <= n; ++i) {
    c[i] = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) <= 96) {
      }
      *sp;
    });
    bs[i] = 1ll * bs[i - 1] * BS % P;
  }
  for (int i = n; --i;) {
    const int x = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    const int y = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    (e[++ei].next = head[x], e[ei].to = (y), head[x] = ei);
    (e[++ei].next = head[y], e[ei].to = (x), head[y] = ei);
  }
  dfs1(1);
  top[1] = 1;
  dfs2(1);
  for (int i = 1; i <= n; ++i) pre[i] = (1ll * pre[i - 1] * BS + c[seg[i]]) % P;
  for (int i = n; i >= 1; --i) suf[i] = (1ll * suf[i + 1] * BS + c[seg[i]]) % P;
  for (int m = ({
         while ((__builtin_expect(++sp == ep, false) &&
                     (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
                 *sp) < 48) {
         }
         _ = *sp ^ 48;
         while ((__builtin_expect(++sp == ep, false) &&
                     (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
                 *sp) >= 48)
           _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
         _;
       });
       m--;) {
    int a = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    int b = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    int c = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    int d = ({
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) < 48) {
      }
      _ = *sp ^ 48;
      while ((__builtin_expect(++sp == ep, false) &&
                  (fread(ibuf, 1, IBUFSIZ, stdin), sp = ibuf),
              *sp) >= 48)
        _ = (((_ << 2) + _) << 1) + (*sp ^ 48);
      _;
    });
    int ans = 0;
    static std::vector<std::pair<int, int>> p1, p2;
    getpath(a, b, p1);
    getpath(c, d, p2);
    it = p1.begin();
    jt = p2.begin();
    while (it != p1.end() && jt != p2.end()) {
      const int f1 = dfn[it->first], t1 = dfn[it->second];
      const int f2 = dfn[jt->first], t2 = dfn[jt->second];
      const bool r1 = f1 > t1, r2 = f2 > t2;
      const int l1 = (r1 ? (f1 - t1) : (t1 - f1)) + 1;
      const int l2 = (r2 ? (f2 - t2) : (t2 - f2)) + 1;
      const int len = std::min(l1, l2);
      if (hash(r1, f1, len) != hash(r2, f2, len)) {
        int l = 0, r = len;
        while (l + 1 < r) {
          const int mid = (l + r) >> 1;
          if (hash(r1, f1, mid) != hash(r2, f2, mid)) {
            r = mid;
          } else {
            l = mid;
          }
        }
        ans += l;
        break;
      }
      if (len == l1) {
        ++it;
      } else {
        it->first = seg[f1 + (r1 ? -len : len)];
      }
      if (len == l2) {
        ++jt;
      } else {
        jt->first = seg[f2 + (r2 ? -len : len)];
      }
      ans += len;
    }
    printf("%d\n", ans);
  }
  return 0;
}