Problem: There is a tree with n vertices. There are also m ants living on it. Each ant has its own color. The i-th ant has two favorite pairs of vertices: (a_i, b_i) and (c_i, d_i). You need to tell if it is possible to paint the edges of the tree in m colors so that every ant will be able to walk between vertices from one of its favorite pairs using only edges of his color; if it is possible, you need to print which pair every ant should use.

Input

The first line contains a single integer n (2 ≤ n ≤ 10^5) — the number of vertices.

Each of the next n-1 lines contains two integers u_i and v_i (1 ≤ u_i, v_i ≤ n), meaning that there is an edge between vertices u_i and v_i.

The next line contains a single integer m (1 ≤ m ≤ 10^4) — the number of ants.

Each of the next m lines contains four integers a_i, b_i, c_i, and d_i (1 ≤ a_i, b_i, c_i, d_i ≤ n, a_i ≠ b_i, c_i ≠ d_i), meaning that pairs (a_i, b_i) and (c_i, d_i) are favorite for the i-th ant.

Output

Print "NO" (without quotes) if the wanted painting is impossible.

Otherwise, print "YES" (without quotes). Print m lines. On the i-th line, print 1 if the i-th ant will use the first pair and 2 otherwise. If there are multiple answers, print any.

Examples

Input

6
1 2
3 1
4 1
5 2
6 2
3
2 6 3 4
1 6 6 5
1 4 5 2


Output

YES
2
1
2


Input

5
1 2
1 3
1 4
1 5
2
2 3 4 5
3 4 5 2


Output

NO

Note

In the sample, the second and the third edge should be painted in the first color, the first and the fifth should be painted in the second color, and the fourth should be painted in the third color.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int a[10000], b[10000], c[10000], d[10000];
vector<int> adjList[100000];
int parent[100000], size[100000], depth[100000], heavy[100000];
int chain[100000], head[100000], disc[100000], csize[100000], num = 0, ch = 0;
int doDFS(int u, int p, int d) {
  int i;
  parent[u] = p, size[u] = 1, depth[u] = d, heavy[u] = -1;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if (v != p) {
      size[u] += doDFS(v, u, d + 1);
      if ((heavy[u] == -1) || (size[v] > size[heavy[u]])) heavy[u] = v;
    }
  }
  return size[u];
}
int doHLD(int u, int p) {
  int i;
  chain[u] = ch, disc[u] = num++;
  if (csize[ch] == 0) head[ch] = u;
  csize[ch]++;
  if (heavy[u] != -1) doHLD(heavy[u], u);
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    if ((v != p) && (v != heavy[u])) ch++, doHLD(v, u);
  }
  return 0;
}
vector<int> tree[1 << 18];
int add(int s, int e, int as, int ae, int i, int u) {
  if ((s > ae) || (e < as))
    return 0;
  else if ((s >= as) && (e <= ae)) {
    tree[i].push_back(u);
    return 0;
  }
  int mid = (s + e) / 2;
  add(s, mid, as, ae, 2 * i + 1, u), add(mid + 1, e, as, ae, 2 * i + 2, u);
  return 0;
}
vector<int> adjList2[5000000];
int process(int s, int e, int i, int u, int u2) {
  int j;
  for (j = 0; j < tree[i].size(); j++) {
    adjList2[tree[i][j]].push_back(u);
    adjList2[num].push_back(u), adjList2[num].push_back(tree[i][j] ^ 1);
    u = num++;
    adjList2[u2].push_back(tree[i][j] ^ 1);
    adjList2[u2].push_back(num), adjList2[tree[i][j]].push_back(num);
    u2 = num++;
  }
  if (s != e) {
    int mid = (s + e) / 2;
    process(s, mid, 2 * i + 1, u, u2), process(mid + 1, e, 2 * i + 2, u, u2);
  }
  return 0;
}
int disc2[5000000], low[5000000], inStack[5000000], num2 = 0;
vector<int> S;
int ans[10000];
int doDFS2(int u, int m) {
  int i;
  disc2[u] = low[u] = num2++;
  S.push_back(u), inStack[u] = 1;
  for (i = 0; i < adjList2[u].size(); i++) {
    int v = adjList2[u][i];
    if (disc2[v] == -1)
      doDFS2(v, m), low[u] = min(low[u], low[v]);
    else if (inStack[v])
      low[u] = min(low[u], disc2[v]);
  }
  if (disc2[u] == low[u]) {
    vector<int> scc;
    while (1) {
      int v = S.back();
      S.pop_back(), inStack[v] = 0;
      scc.push_back(v);
      if (u == v) break;
    }
    for (i = 0; i < scc.size(); i++) {
      if ((scc[i] < 2 * m) && (ans[scc[i] >> 1] != 0)) break;
    }
    if (i == scc.size()) {
      for (i = 0; i < scc.size(); i++) {
        if (scc[i] < 2 * m) {
          if (ans[scc[i] >> 1] != 0)
            ans[scc[i] >> 1] = 0;
          else
            ans[scc[i] >> 1] = (scc[i] & 1) + 1;
        }
      }
    }
  }
  return 0;
}
int main() {
  int i;
  int n, m, u, v;
  scanf("%d", &n);
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &u, &v);
    u--, v--;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  scanf("%d", &m);
  for (i = 0; i < m; i++)
    scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]), a[i]--, b[i]--, c[i]--,
        d[i]--;
  doDFS(0, -1, 0), doHLD(0, -1), ch++;
  for (i = 0; i < m; i++) {
    u = a[i], v = b[i];
    while (chain[u] != chain[v]) {
      if (depth[head[chain[u]]] < depth[head[chain[v]]]) swap(u, v);
      add(0, n - 1, disc[head[chain[u]]], disc[u], 0, 2 * i);
      u = parent[head[chain[u]]];
    }
    if (depth[u] > depth[v]) swap(u, v);
    add(0, n - 1, disc[u] + 1, disc[v], 0, 2 * i);
    u = c[i], v = d[i];
    while (chain[u] != chain[v]) {
      if (depth[head[chain[u]]] < depth[head[chain[v]]]) swap(u, v);
      add(0, n - 1, disc[head[chain[u]]], disc[u], 0, 2 * i + 1);
      u = parent[head[chain[u]]];
    }
    if (depth[u] > depth[v]) swap(u, v);
    add(0, n - 1, disc[u] + 1, disc[v], 0, 2 * i + 1);
  }
  num = 2 * m + 2;
  process(0, n - 1, 0, num - 2, num - 1);
  for (i = 0; i < num; i++) disc2[i] = low[i] = -1;
  for (i = 0; i < num; i++) {
    if (disc2[i] == -1) doDFS2(i, m);
  }
  for (i = 0; i < m; i++) {
    if (ans[i] == 0) break;
  }
  if (i < m)
    printf("NO\n");
  else {
    printf("YES\n");
    for (i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
  return 0;
}