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 inf = int(1e9);
const double eps = 1e-4;
const double pi = 4 * atan(double(1));
const int LOG = 19;
const int N = int(3e5) + 100;
const int M = int(1e6) + 100;
const int X = 4243;
const int MOD = int(1e9) + 7;
struct _hash {
  int a;
  _hash() {}
  _hash(int a) : a(a) {}
};
_hash operator+(const _hash &a, const _hash &b) {
  _hash c(a.a + b.a);
  if (c.a >= MOD) {
    c.a -= MOD;
  }
  return c;
}
_hash operator-(const _hash &a, const _hash &b) {
  _hash c(a.a - b.a);
  if (c.a < 0) {
    c.a += MOD;
  }
  return c;
}
_hash operator*(const _hash &a, const _hash &b) {
  return _hash((1LL * a.a * b.a) % MOD);
}
bool operator==(const _hash &a, const _hash &b) { return a.a == b.a; }
struct tq {
  int a, b, ab, c, d, cd;
};
int n, shift, sz;
bool used[N];
char s[N];
int _prev[N], _rank[N], val[N], h[N], p[N];
_hash pw[2 * N], sum[N], rev_sum[N];
int last_bit[3 * N];
vector<pair<int, int *> > lca[N];
tq q[M];
int *ptr[N][LOG];
int *cur[LOG];
vector<int> g[N];
int get(int a) {
  if (_prev[a] != a) {
    _prev[a] = get(_prev[a]);
  }
  return _prev[a];
}
inline void merge(int a, int b, int c) {
  a = get(a);
  b = get(b);
  if (_rank[a] < _rank[b]) {
    swap(a, b);
  }
  _prev[b] = a;
  if (_rank[a] == _rank[b]) {
    ++_rank[a];
  }
  val[a] = c;
}
void dfs(int v, int pv) {
  int *mem[LOG];
  for (int i = 0; i < LOG; ++i) {
    mem[i] = cur[i];
  }
  if ((sz & 1) == 0) {
    cur[0] = new int[1];
    cur[0][0] = v;
  } else {
    int ptr = 0;
    while (ptr + 1 < LOG && (sz & (1 << (ptr + 1))) != 0) {
      ++ptr;
    }
    cur[ptr + 1] = new int[(1 << (ptr + 1))];
    int p = 0;
    for (int i = ptr; i >= 0; --i) {
      for (int j = 0; j < (1 << i); ++j) {
        cur[ptr + 1][p++] = cur[i][j];
      }
      cur[i] = NULL;
    }
    cur[ptr + 1][p++] = v;
  }
  ++sz;
  for (int i = 0; i < LOG; ++i) {
    ptr[v][i] = cur[i];
  }
  used[v] = true;
  p[v] = pv;
  if (pv == -1) {
    h[v] = 0;
    sum[v] = pw[0] * _hash(s[v]);
    rev_sum[v] = pw[n] * _hash(s[v]);
  } else {
    g[v].erase(find((g[v]).begin(), (g[v]).end(), pv));
    h[v] = h[pv] + 1;
    sum[v] = sum[pv] + pw[h[v]] * _hash(s[v]);
    rev_sum[v] = rev_sum[pv] + pw[n - h[v]] * _hash(s[v]);
  }
  for (int i = 0; i < int((lca[v]).size()); ++i) {
    if (used[lca[v][i].first]) {
      *(lca[v][i].second) = val[get(lca[v][i].first)];
    }
  }
  for (int i = 0; i < int((g[v]).size()); ++i) {
    dfs(g[v][i], v);
    merge(v, g[v][i], v);
  }
  for (int i = 0; i < LOG; ++i) {
    cur[i] = mem[i];
  }
  --sz;
}
inline int len(int a, int b, int ab) { return h[a] + h[b] - 2 * h[ab] + 1; }
inline int get_ver(int v, int len) {
  int sz = h[v] + 1 + shift;
  int bit = last_bit[sz ^ (sz - len)];
  len -= (sz & ((1 << bit) - 1));
  return ptr[v][bit][(1 << bit) - len];
}
inline _hash get_rev_sum(int v, int pv) {
  return (rev_sum[v] - (p[pv] == -1 ? _hash(0) : rev_sum[p[pv]])) * pw[h[v]];
}
inline _hash get_hash(int a, int b, int ab, int len) {
  if (len <= h[a] - h[ab] + 1) {
    return get_rev_sum(a, get_ver(a, len));
  }
  len -= h[a] - h[ab] + 1;
  int push_back = get_ver(b, h[b] - h[ab]);
  return get_rev_sum(a, ab) +
         (sum[get_ver(b, h[b] - h[ab] - len + 1)] - sum[ab]) *
             pw[n + (h[a] - h[ab] + 1) - h[push_back]];
}
int main() {
  scanf("%d", &n);
  gets(s);
  gets(s);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  pw[0] = _hash(1);
  for (int i = 1; i <= 2 * n; ++i) {
    pw[i] = pw[i - 1] * X;
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d %d", &q[i].a, &q[i].b, &q[i].c, &q[i].d);
    --q[i].a;
    --q[i].b;
    --q[i].c;
    --q[i].d;
    lca[q[i].a].push_back(make_pair(q[i].b, &q[i].ab));
    lca[q[i].b].push_back(make_pair(q[i].a, &q[i].ab));
    lca[q[i].c].push_back(make_pair(q[i].d, &q[i].cd));
    lca[q[i].d].push_back(make_pair(q[i].c, &q[i].cd));
  }
  for (int i = 0; i < n; ++i) {
    _prev[i] = i;
    _rank[i] = 1;
    val[i] = i;
  }
  for (int i = 0; i < LOG; ++i) {
    cur[i] = NULL;
  }
  sz = 0;
  shift = 1 + rand() % 3333;
  for (int i = 0; i < shift; ++i) {
    if (sz == 0) {
      cur[0] = new int[1];
      cur[0][0] = -1;
    } else {
      if ((sz & 1) == 0) {
        cur[0] = new int[1];
        cur[0][0] = -1;
      } else {
        int ptr = 0;
        while (ptr + 1 < LOG && (sz & (1 << (ptr + 1))) != 0) {
          ++ptr;
        }
        cur[ptr + 1] = new int[(1 << (ptr + 1))];
        int p = 0;
        for (int j = ptr; j >= 0; --j) {
          for (int z = 0; z < (1 << j); ++z) {
            cur[ptr + 1][p++] = cur[j][z];
          }
          cur[j] = NULL;
        }
        cur[ptr + 1][p++] = -1;
      }
    }
    ++sz;
  }
  dfs(0, -1);
  for (int i = 1; i <= 2 * (n + shift) + 100; ++i) {
    for (int j = LOG - 1; j >= 0; --j) {
      if ((i & (1 << j)) != 0) {
        last_bit[i] = j;
        break;
      }
    }
  }
  cerr << get_ver(5, 1) << endl;
  cerr << get_ver(5, 2) << endl;
  for (int i = 0; i < m; ++i) {
    int ans = 0, l = 1,
        r = min(len(q[i].a, q[i].b, q[i].ab), len(q[i].c, q[i].d, q[i].cd));
    while (l <= r) {
      int mid = (l + r) / 2;
      _hash h1 = get_hash(q[i].a, q[i].b, q[i].ab, mid);
      _hash h2 = get_hash(q[i].c, q[i].d, q[i].cd, mid);
      if (h1 == h2) {
        ans = mid;
        l = mid + 1;
      } else {
        r = mid - 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}