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 two_sat {
  static const int MAXV = 1.1e6;
  int V;
  vector<int> implies[MAXV * 2];
  int new_var() {
    assert(V < MAXV);
    return ((V++) * 2 + 1);
  }
  inline int n(int a) { return a ^ 1; }
  void constrain(int a, int b) {
    if (a < 0 || b < 0) return;
    implies[a].push_back(b);
    implies[n(b)].push_back(n(a));
  }
  int make_and(int a, int b) {
    if (a < 0) return b;
    if (b < 0) return a;
    int v = new_var();
    constrain(v, a);
    constrain(v, b);
    return v;
  }
  int make_or(int a, int b) {
    if (a < 0) return b;
    if (b < 0) return a;
    int v = new_var();
    constrain(a, v);
    constrain(b, v);
    return v;
  }
  int make_at_most_one(int a, int b) {
    if (a < 0) return b;
    if (b < 0) return a;
    constrain(a, n(b));
    return make_or(a, b);
  }
  bool solution[MAXV * 2];
  bool vis[2][MAXV * 2];
  int q[2][MAXV * 2];
  bool solve() {
    for (int i = 0; i < 2 * V; i++) {
      solution[i] = false;
      vis[0][i] = vis[1][i] = false;
    }
    for (int i = 0; i < V; i++) {
      if (!solution[2 * i + 0] && !solution[2 * i + 1]) {
        bool bad[2] = {false, false};
        int qs[2] = {0, 0};
        int qi[2] = {0, 0};
        int qt[2] = {0, 0};
        for (int z = 0; z < 2; z++) {
          vis[z][2 * i + z] = true;
          q[z][qt[z]++] = 2 * i + z;
        }
        while (true) {
          if (bad[0] && bad[1]) {
            return false;
          }
          for (int z = 0; z < 2; z++) {
            if (bad[z]) continue;
            if (qs[z] >= qt[z]) {
              for (int ind = 0; ind < qt[z]; ind++) {
                solution[q[z][ind]] = true;
              }
              bad[!z] = true;
              goto done;
            }
            int v = q[z][qs[z]];
            if (qi[z] == int(implies[v].size())) {
              qs[z]++;
              qi[z] = 0;
              continue;
            }
            int u = implies[v][qi[z]];
            assert(!solution[n(u)]);
            if (vis[z][n(u)]) {
              bad[z] = true;
            } else if (!solution[u] && !vis[z][u]) {
              vis[z][u] = true;
              q[z][qt[z]++] = u;
            }
            qi[z]++;
          }
        }
      done:
        assert(bad[0] + bad[1] == 1);
        for (int z = 0; z < 2; z++) {
          for (int ind = 0; ind < qt[z]; ind++) {
            vis[z][q[z][ind]] = false;
          }
        }
      }
      assert(solution[2 * i + 0] + solution[2 * i + 1] == 1);
    }
    return true;
  }
} ts;
const int MAXN = int(1e5) + 20;
int N;
vector<int> adj[MAXN];
int depth[MAXN];
int par[MAXN][20];
int sz[MAXN];
int lca(int a, int b) {
  if (depth[a] != depth[b]) {
    if (depth[a] > depth[b]) swap(a, b);
    assert(depth[b] > depth[a]);
    int d = depth[b] - depth[a];
    assert(d > 0);
    for (int i = 0; (1 << i) <= d; i++) {
      if (d & (1 << i)) b = par[b][i];
    }
  }
  if (a == b) return a;
  int i = 0;
  while (par[a][i] != par[b][i]) i++;
  assert(par[a][i] == par[b][i]);
  for (; i > 0; i--) {
    assert(par[a][i] == par[b][i]);
    if (par[a][i - 1] != par[b][i - 1]) {
      a = par[a][i - 1];
      b = par[b][i - 1];
    }
    assert(par[a][i - 1] == par[b][i - 1]);
  }
  return par[a][0];
}
void dfs_lca(int cur, int prv = 0) {
  depth[cur] = depth[prv] + 1;
  par[cur][0] = prv;
  for (int i = 0; par[cur][i] != 0; i++) {
    par[cur][i + 1] = par[par[cur][i]][i];
  }
  sz[cur] = 1;
  for (int nxt : adj[cur]) {
    if (nxt == prv) continue;
    dfs_lca(nxt, cur);
    sz[cur] += sz[nxt];
  }
}
int hld_ind[MAXN];
int hld_top[MAXN];
void dfs_hld(int cur = 1, int prv = 0, int hpar = 1, int ind = 1) {
  hld_ind[cur] = ind;
  hld_top[cur] = hpar;
  ind++;
  for (int nxt : adj[cur]) {
    if (nxt == prv) continue;
    if (sz[nxt] * 2 >= sz[cur]) {
      dfs_hld(nxt, cur, hpar, ind);
      ind += sz[nxt];
      break;
    }
  }
  for (int nxt : adj[cur]) {
    if (nxt == prv) continue;
    if (sz[nxt] * 2 >= sz[cur]) {
      continue;
    }
    dfs_hld(nxt, cur, nxt, ind);
    ind += sz[nxt];
  }
  assert(ind == hld_ind[cur] + sz[cur]);
}
const int S = 1 << 17;
int seg[S * 2];
const int MAXM = 1.1e4;
int M;
int ant_vars[MAXM];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  depth[0] = 0;
  dfs_lca(1);
  hld_ind[0] = 0;
  hld_top[0] = 0;
  dfs_hld();
  memset(seg, -1, sizeof(seg));
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    int v = ts.new_var();
    ant_vars[i] = v;
    for (int z = 0; z < 2; z++, v = ts.n(v)) {
      int a[2];
      scanf("%d %d", &a[0], &a[1]);
      int c = lca(a[0], a[1]);
      for (int y = 0; y < 2; y++) {
        int cur = a[y];
        while (cur != c) {
          int nxt;
          int top = hld_top[cur];
          int l, r;
          if (depth[top] > depth[c]) {
            nxt = par[top][0];
            l = hld_ind[top];
            r = hld_ind[cur];
          } else {
            assert(hld_top[c] == top);
            nxt = c;
            l = hld_ind[c] + 1;
            r = hld_ind[cur];
          }
          r++;
          for (l += S, r += S; l < r; l /= 2, r /= 2) {
            if (l & 1) {
              seg[l] = ts.make_at_most_one(seg[l], v);
              l++;
            }
            if (r & 1) {
              r--;
              seg[r] = ts.make_at_most_one(seg[r], v);
            }
          }
          cur = nxt;
        }
      }
    }
  }
  for (int i = S - 1; i > 0; i--) {
    seg[i] =
        ts.make_at_most_one(seg[i], ts.make_or(seg[2 * i + 0], seg[2 * i + 1]));
  }
  if (ts.solve()) {
    printf("YES\n");
    for (int i = 0; i < M; i++) {
      printf("%c\n", ts.solution[ant_vars[i]] ? '1' : '2');
    }
  } else {
    printf("NO\n");
  }
  return 0;
}