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;
struct SAT {
  int N;
  vector<int> edge[2000050 * 2];
  vector<int> redge[2000050 * 2];
  int new_var() {
    assert(N < 2000050);
    N++;
    return N * 2 - 2;
  }
  int rev(int a) { return (a ^ 1); }
  void add_edge(int u, int v) {
    if (u < 0 || v < 0) return;
    edge[u].push_back(v);
    edge[rev(v)].push_back(rev(u));
    redge[v].push_back(u);
    redge[rev(u)].push_back(rev(v));
  }
  int make_and(int u, int v) {
    if (u < 0) return v;
    if (v < 0) return u;
    int ret = new_var();
    add_edge(ret, u);
    add_edge(ret, v);
    return ret;
  }
  int make_or(int u, int v) {
    if (u < 0) return v;
    if (v < 0) return u;
    int ret = new_var();
    add_edge(u, ret);
    add_edge(v, ret);
    return ret;
  }
  int make_only(int u, int v) {
    if (u < 0) return v;
    if (v < 0) return u;
    add_edge(u, rev(v));
    return make_or(u, v);
  }
  vector<int> used, vert, comp;
  int id;
  void dfs(int v) {
    if (used[v]) return;
    used[v] = 1;
    for (int i = 0; i < edge[v].size(); i++) {
      if (!used[edge[v][i]]) {
        dfs(edge[v][i]);
      }
    }
    vert[id++] = v;
  }
  void sfd(int v) {
    if (used[v]) return;
    used[v] = 1;
    comp[v] = id;
    for (int i = 0; i < redge[v].size(); i++) {
      if (!used[redge[v][i]]) {
        sfd(redge[v][i]);
      }
    }
  }
  vector<int> ans;
  bool solve() {
    used.resize(2000050 * 2, 0);
    vert.resize(2000050 * 2, 0);
    comp.resize(2000050 * 2, 0);
    id = 0;
    for (int i = 0; i < 2000050 * 2; i++) {
      if (!used[i]) {
        dfs(i);
      }
    }
    fill(used.begin(), used.end(), 0);
    id = 0;
    for (int i = 2000050 * 2 - 1; i >= 0; i--) {
      if (!used[vert[i]]) {
        sfd(vert[i]);
        id++;
      }
    }
    ans.resize(2000050 * 2, 0);
    for (int i = 0; i < 2000050; i++) {
      if (comp[i * 2] == comp[i * 2 + 1]) {
        return false;
      }
      if (comp[i * 2] > comp[i * 2 + 1]) {
        ans[i * 2] = 1;
      } else {
        ans[i * 2 + 1] = 1;
      }
    }
    return true;
  }
} solver;
int n, m;
int base[10005];
vector<int> G[100005];
int dep[100005];
int up[100005][20];
int cnt[100005];
void dfs(int v, int u) {
  up[v][0] = u;
  if (u == -1)
    dep[v] = 0;
  else
    dep[v] = dep[u] + 1;
  cnt[v] = 1;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == u) continue;
    dfs(G[v][i], v);
    cnt[v] += cnt[G[v][i]];
  }
}
int hld_cmp[100005], hld_num[100005], hld_sz[100005];
void make_hld(int v, int u, int up, int id) {
  hld_cmp[v] = up;
  hld_num[v] = id;
  hld_sz[up] = max(hld_sz[up], id);
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == u) continue;
    if (cnt[G[v][i]] * 2 >= cnt[v]) {
      make_hld(G[v][i], v, up, id + 1);
    } else {
      make_hld(G[v][i], v, G[v][i], 1);
    }
  }
}
struct segtree {
  vector<int> seg;
  int sz = 0;
  void init(int SZ) {
    while (SZ + 5 >= (1 << sz)) sz++;
    seg.resize((2 << sz), -1);
  }
  void query(int a, int b, int k, int l, int r, int node) {
    if (r < a || b < l) return;
    if (a <= l && r <= b) {
      seg[k] = solver.make_only(seg[k], node);
      return;
    }
    query(a, b, k * 2 + 1, l, (l + r) / 2, node);
    query(a, b, k * 2 + 2, (l + r) / 2 + 1, r, node);
  }
  void query(int a, int b, int node) {
    return query(a, b, 0, 0, (1 << sz) - 1, node);
  }
  void final() {
    for (int i = (1 << sz) - 2; i >= 0; i--) {
      seg[i] = solver.make_only(seg[i],
                                solver.make_or(seg[i * 2 + 1], seg[i * 2 + 2]));
    }
  }
} hld[100005];
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--) {
    if ((1 << i) <= (dep[v] - dep[u])) {
      v = up[v][i];
    }
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (up[u][i] != up[v][i]) {
      u = up[u][i];
      v = up[v][i];
    }
  }
  return up[u][0];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, -1);
  for (int j = 0; j < 19; j++) {
    for (int i = 1; i <= n; i++) {
      if (up[i][j] == -1)
        up[i][j + 1] = -1;
      else
        up[i][j + 1] = up[up[i][j]][j];
    }
  }
  make_hld(1, -1, 1, 1);
  for (int i = 1; i <= n; i++) {
    if (hld_sz[i] == 0) continue;
    hld[i].init(hld_sz[i]);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    base[i] = solver.new_var();
    int p, q, r;
    scanf("%d%d", &p, &q);
    r = lca(p, q);
    while (r != p) {
      int upp = hld_cmp[p], nxt;
      if (dep[r] < dep[upp]) {
        hld[upp].query(0, hld_num[p] - 1, base[i]);
        nxt = up[upp][0];
      } else {
        hld[upp].query(hld_num[r], hld_num[p] - 1, base[i]);
        nxt = r;
      }
      p = nxt;
    }
    while (r != q) {
      int upp = hld_cmp[q], nxt;
      if (dep[r] < dep[upp]) {
        hld[upp].query(0, hld_num[q] - 1, base[i]);
        nxt = up[upp][0];
      } else {
        hld[upp].query(hld_num[r], hld_num[q] - 1, base[i]);
        nxt = r;
      }
      q = nxt;
    }
    base[i] = solver.rev(base[i]);
    scanf("%d%d", &p, &q);
    r = lca(p, q);
    while (r != p) {
      int upp = hld_cmp[p], nxt;
      if (dep[r] < dep[upp]) {
        hld[upp].query(0, hld_num[p] - 1, base[i]);
        nxt = up[upp][0];
      } else {
        hld[upp].query(hld_num[r], hld_num[p] - 1, base[i]);
        nxt = r;
      }
      p = nxt;
    }
    while (r != q) {
      int upp = hld_cmp[q], nxt;
      if (dep[r] < dep[upp]) {
        hld[upp].query(0, hld_num[q] - 1, base[i]);
        nxt = up[upp][0];
      } else {
        hld[upp].query(hld_num[r], hld_num[q] - 1, base[i]);
        nxt = r;
      }
      q = nxt;
    }
    base[i] = solver.rev(base[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (hld_sz[i] == 0) continue;
    hld[i].final();
  }
  if (solver.solve()) {
    puts("YES");
    for (int i = 1; i <= m; i++) {
      printf("%d\n", 2 - solver.ans[base[i]]);
    }
  } else {
    puts("NO");
  }
}