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 mod1 = 998244353, mod2 = 1e9 + 7;
struct Hash {
  int fir, sec;
  Hash(int _f, int _s) : fir(_f), sec(_s) {}
  Hash() {}
  Hash operator+(const int d) {
    return Hash((fir + d) % mod1, (sec + d) % mod2);
  }
  Hash operator+(const Hash d) {
    return Hash((fir + d.fir) % mod1, (sec + d.sec) % mod2);
  }
  Hash operator-(const Hash d) {
    return Hash((fir - d.fir + mod1) % mod1, (sec - d.sec + mod2) % mod2);
  }
  Hash operator*(const Hash d) {
    return Hash(1ll * fir * d.fir % mod1, 1ll * sec * d.sec % mod2);
  }
  bool operator!=(const Hash d) const {
    return !(fir == d.fir && sec == d.sec);
  }
  bool operator==(const Hash d) const { return (fir == d.fir && sec == d.sec); }
};
const int N = 3e5 + 5;
const Hash base = Hash(13331, 9797987);
int abs(int n) { return (n > 0) ? n : -n; }
struct EDGE {
  int to, next;
} edge[N << 1];
struct Pair {
  int u, v, pu, pv;
  Pair() {}
  Pair(int _u, int _v, int _pu = 0, int _pv = 0)
      : u(_u), v(_v), pu(_pu), pv(_pv) {}
};
int n, head[N], son[N], top[N], siz[N], fa[N], dfn[N], pos[N], dep[N], dfstime,
    tail;
Hash pre[N], suf[N], pw[N];
char ch[N];
void AddEdge(int u, int v) {
  edge[++tail].to = v;
  edge[tail].next = head[u];
  head[u] = tail;
}
void Dfs1(int now, int from) {
  fa[now] = from;
  siz[now] = 1;
  dep[now] = dep[from] + 1;
  for (int i = head[now]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to != from) {
      Dfs1(to, now);
      siz[now] += siz[to];
      if (siz[son[now]] < siz[to]) son[now] = to;
    }
  }
}
void Dfs2(int now) {
  dfn[++dfstime] = now;
  pos[now] = dfstime;
  if (son[now]) {
    top[son[now]] = top[now];
    Dfs2(son[now]);
  }
  for (int i = head[now]; i; i = edge[i].next) {
    int to = edge[i].to;
    if (to != fa[now] && to != son[now]) {
      top[to] = to;
      Dfs2(to);
    }
  }
}
Hash Query(int st, int ed) {
  if (st > ed)
    return suf[ed] - suf[st + 1] * pw[st - ed + 1];
  else
    return pre[ed] - pre[st - 1] * pw[ed - st + 1];
}
void Swap(int &u, int &v) { u ^= v ^= u ^= v; }
int Lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) Swap(u, v);
    u = fa[top[u]];
  }
  return (dep[u] > dep[v]) ? v : u;
}
vector<Pair> Divide(int u, int v) {
  static vector<Pair> ret, tmp;
  ret.clear(), tmp.clear();
  int lca = Lca(u, v);
  while (top[u] != top[lca]) {
    ret.push_back(Pair(pos[u], pos[top[u]]));
    u = fa[top[u]];
  }
  while (top[v] != top[lca]) {
    tmp.push_back(Pair(pos[top[v]], pos[v]));
    v = fa[top[v]];
  }
  ret.push_back(Pair(pos[u], pos[v]));
  for (int i = tmp.size() - 1; i >= 0; --i) ret.push_back(tmp[i]);
  int pt = 1;
  for (int i = 0; i < ret.size(); ++i) {
    ret[i].pu = pt;
    pt += abs(ret[i].u - ret[i].v) + 1;
    ret[i].pv = pt - 1;
  }
  return ret;
}
int Extend(int u, int v, int len) {
  if (u < v)
    return u + len - 1;
  else
    return u - len + 1;
}
int duan[N], tt;
int main() {
  scanf("%d", &n);
  scanf("%s", ch + 1);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    AddEdge(u, v);
    AddEdge(v, u);
  }
  Dfs1(1, 0);
  top[1] = 1;
  Dfs2(1);
  pw[0] = Hash(1, 1);
  for (int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * base;
  for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] * base + (ch[dfn[i]] - 'a');
  for (int i = n; i >= 1; --i) suf[i] = suf[i + 1] * base + (ch[dfn[i]] - 'a');
  int nbQ;
  scanf("%d", &nbQ);
  while (nbQ--) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    vector<Pair> fir = Divide(a, b);
    vector<Pair> sec = Divide(c, d);
    vector<Pair> splFir, splSec;
    while (splFir.size()) splFir.pop_back();
    while (splSec.size()) splSec.pop_back();
    tt = 0;
    int mn = min(fir[fir.size() - 1].pv, sec[sec.size() - 1].pv);
    for (int i = 0; i < fir.size(); ++i) {
      if (fir[i].pv > mn) break;
      duan[++tt] = fir[i].pv;
    }
    for (int i = 0; i < sec.size(); ++i) {
      if (sec[i].pv > mn) break;
      duan[++tt] = sec[i].pv;
    }
    sort(duan + 1, duan + tt + 1);
    tt = unique(duan + 1, duan + tt + 1) - (duan + 1);
    int pt = 0;
    for (int i = 1; i <= tt; ++i) {
      if (duan[i - 1] + 1 > fir[fir.size() - 1].pv) break;
      splFir.push_back(Pair(0, 0, duan[i - 1] + 1, duan[i]));
      while (fir[pt].pv < splFir[i - 1].pu) ++pt;
      int add = (fir[pt].u == fir[pt].v)
                    ? 1
                    : (abs(fir[pt].v - fir[pt].u) / (fir[pt].v - fir[pt].u));
      splFir[i - 1].u = fir[pt].u + add * (splFir[i - 1].pu - fir[pt].pu);
      splFir[i - 1].v = fir[pt].u + add * (splFir[i - 1].pv - fir[pt].pu);
    }
    pt = 0;
    for (int i = 1; i <= tt; ++i) {
      if (duan[i - 1] + 1 > sec[sec.size() - 1].pv) break;
      splSec.push_back(Pair(0, 0, duan[i - 1] + 1, duan[i]));
      while (sec[pt].pv < splSec[i - 1].pu) ++pt;
      int add = (sec[pt].u == sec[pt].v)
                    ? 1
                    : (abs(sec[pt].v - sec[pt].u) / (sec[pt].v - sec[pt].u));
      splSec[i - 1].u = sec[pt].u + add * (splSec[i - 1].pu - sec[pt].pu);
      splSec[i - 1].v = sec[pt].u + add * (splSec[i - 1].pv - sec[pt].pu);
    }
    int ans = 0;
    for (int i = 0; i < min(splFir.size(), splSec.size()); ++i) {
      if (Query(splSec[i].u, splSec[i].v) != Query(splFir[i].u, splFir[i].v)) {
        int ttt = 0, L = 1, R = splFir[i].pv - splFir[i].pu + 1;
        while (L <= R) {
          int mid = (L + R) >> 1;
          int edSec = Extend(splSec[i].u, splSec[i].v, mid);
          int edFir = Extend(splFir[i].u, splFir[i].v, mid);
          if (Query(splSec[i].u, edSec) == Query(splFir[i].u, edFir))
            ttt = mid, L = mid + 1;
          else
            R = mid - 1;
        }
        ans += ttt;
        break;
      } else {
        ans = splFir[i].pv;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}