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;
struct debug_t {
  template <typename T>
  debug_t& operator<<(const T& value) {
    return *this;
  }
  debug_t& write(const char data[], streamsize n) { return *this; }
} debug;
int bsf(int x) { return __builtin_ctz(x); }
int bsr(int x) { return 31 - __builtin_clz(x); }
int gid;
template <class Node, int N>
struct Lca {
  Node* lp[N + 1];
  int height[N + 1];
  void init(Node* root) {
    gid = 1;
    root->mask = 0x0;
    _dfs0(root, nullptr);
    _dfs1(root, nullptr, 0);
  }
  Node* get(Node* x, Node* y) {
    const auto dpx = x->deepestId, dpy = y->deepestId;
    if (dpx != dpy) {
      const auto k = bsr(dpx ^ dpy);
      const auto zh =
          bsf(x->mask & y->mask & ~0 << height[(dpx >> k | 0x1) << k]);
      if (bsf(x->mask) != zh) x = _raise(dpx, x->mask, zh);
      if (bsf(y->mask) != zh) y = _raise(dpy, y->mask, zh);
    }
    return x->id < y->id ? x : y;
  }

 private:
  int _dfs0(Node* self, const Node* prev) {
    self->id = self->deepestId = gid++;
    int h = bsf(self->id);
    for (const auto node : self->adj)
      if (node != prev) {
        const auto t = _dfs0(node, self);
        if (t > h) {
          h = t;
          self->deepestId = node->deepestId;
        }
        lp[node->deepestId] = self;
      }
    height[self->id] = h;
    return h;
  }
  void _dfs1(Node* self, const Node* prev, int index) {
    self->indexInLine = index;
    self->mask |= self->deepestId & -self->deepestId;
    for (const auto node : self->adj)
      if (node != prev) {
        node->mask = self->mask;
        _dfs1(node, self, node->deepestId == self->deepestId ? index + 1 : 0);
      }
  }
  Node* _raise(int deepestId, int mask, int zh) {
    const auto k = bsr(mask & ((1 << zh) - 1));
    return lp[(deepestId >> k | 0x1) << k];
  }
};
struct AutoNode;
AutoNode* createNode(int len);
AutoNode* createNode(const AutoNode&);
struct AutoNode {
  int len;
  unordered_map<char, AutoNode*> next;
  AutoNode* link;
  vector<AutoNode*> adj;
  int id, deepestId, mask, indexInLine;
  AutoNode() : len(0), link(nullptr) {}
  explicit AutoNode(int len) : len(len) {}
  AutoNode* append(char c, AutoNode* last) {
    auto cur = createNode(last->len + 1);
    unordered_map<char, AutoNode*>::iterator it;
    while ((it = last->next.find(c)) == last->next.end()) {
      last->next.emplace(c, cur);
      last = last->link;
      if (!last) {
        cur->link = this;
        return cur;
      }
    }
    const auto q = it->second;
    if (q->len == last->len + 1) {
      cur->link = q;
      return cur;
    }
    const auto clone = createNode(*q);
    clone->len = last->len + 1;
    cur->link = q->link = clone;
    do {
      it->second = clone;
      last = last->link;
      if (!last) break;
      it = last->next.find(c);
    } while (it != last->next.end() && it->second == q);
    return cur;
  }
};
int strSize;
char str[300000];
struct TreeNode {
  char c;
  vector<TreeNode*> adj;
  int id, deepestId, mask, indexInLine, indexInString;
  void genString(const TreeNode* prev) {
    indexInString = strSize;
    str[strSize++] = c;
    for (const auto node : adj)
      if (node != prev && node->deepestId == deepestId) {
        node->genString(this);
        break;
      }
    for (const auto node : adj)
      if (node != prev && node->deepestId != deepestId) node->genString(this);
  }
};
struct Waypoint {
  int pos, lpos, trgLpos;
  bool up;
};
int n;
TreeNode nodes[300000];
int auNodesSize;
AutoNode auNodes[1200000];
AutoNode* tdNodes[300000];
AutoNode* buNodes[300000];
Lca<TreeNode, 300000> treeLca;
Lca<AutoNode, 1200000> auLca;
Waypoint wp[2][38];
AutoNode* createNode(int len) {
  auNodes[auNodesSize] = AutoNode(len);
  return &auNodes[auNodesSize++];
}
AutoNode* createNode(const AutoNode& node) {
  auNodes[auNodesSize] = node;
  return &auNodes[auNodesSize++];
}
int calcWaypoints(TreeNode* a, TreeNode* b, Waypoint wp[]) {
  const auto lca = treeLca.get(a, b);
  int i = 0;
  auto walkUp = [&](const TreeNode* node, bool up) {
    while (node->deepestId != lca->deepestId) {
      wp[i++] = {node->indexInString, node->indexInLine, 0, up};
      node = treeLca.lp[node->deepestId];
    }
    if (up)
      wp[i++] = {node->indexInString, node->indexInLine, lca->indexInLine, up};
    else if (node != lca)
      wp[i++] = {node->indexInString, node->indexInLine, lca->indexInLine + 1,
                 up};
  };
  walkUp(a, true);
  const auto mid = i;
  walkUp(b, false);
  reverse(wp + mid, wp + i);
  return i;
}
int solve(TreeNode* a, TreeNode* b, TreeNode* c, TreeNode* d) {
  const auto n = calcWaypoints(a, b, wp[0]);
  const auto m = calcWaypoints(c, d, wp[1]);
  int result = 0, i = 0, j = 0;
  while (i < n && j < m) {
    auto& a = wp[0][i];
    auto& c = wp[1][j];
    auto node0 = a.up ? buNodes[a.pos] : tdNodes[a.pos - a.lpos + a.trgLpos];
    auto node1 = c.up ? buNodes[c.pos] : tdNodes[c.pos - c.lpos + c.trgLpos];
    const auto aLim = a.lpos - a.trgLpos + 1;
    const auto cLim = c.lpos - c.trgLpos + 1;
    const auto lce = min(auLca.get(node0, node1)->len, min(aLim, cLim));
    result += lce;
    if (lce < aLim && lce < cLim) return result;
    if (lce == aLim)
      i++;
    else if (a.up) {
      a.pos -= lce;
      a.lpos -= lce;
    } else
      a.trgLpos += lce;
    if (lce == cLim)
      j++;
    else if (c.up) {
      c.pos -= lce;
      c.lpos -= lce;
    } else
      c.trgLpos += lce;
  }
  return result;
}
int main() {
  int i;
  while (scanf("%d ", &n) == 1) {
    for (i = 0; i < n; i++) {
      nodes[i].c = (char)getchar();
    }
    for (i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      a--;
      b--;
      nodes[a].adj.push_back(&nodes[b]);
      nodes[b].adj.push_back(&nodes[a]);
    }
    treeLca.init(&nodes[0]);
    strSize = 0;
    nodes[0].genString(nullptr);
    AutoNode root;
    auNodesSize = 0;
    auto last = &root;
    for (i = n - 1; i >= 0; i--) last = tdNodes[i] = root.append(str[i], last);
    for (i = 0; i < n; i++) last = buNodes[i] = root.append(str[i], last);
    for (i = 0; i < auNodesSize; i++)
      auNodes[i].link->adj.push_back(&auNodes[i]);
    auLca.init(&root);
    int q;
    scanf("%d", &q);
    while (q--) {
      int a, b, c, d;
      scanf("%d%d%d%d", &a, &b, &c, &d);
      printf("%d\n",
             solve(&nodes[a - 1], &nodes[b - 1], &nodes[c - 1], &nodes[d - 1]));
    }
  }
  fflush(stdout);
  _Exit(0);
}