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>
const int N = 100054, M = N * 2;
int n, m, V, E = 0;
int to[M], first[N], next[M];
int p[N], dep[N], size[N];
int cnt = 0, o[N], id[N], prf[N], len[N], top[N];
int tmp[N], dak[N];
int ant[N];
std::vector<int> mc[N];
inline void up(int &x, const int y) { x < y ? x = y : 0; }
inline void down(int &x, const int y) { x > y ? x = y : 0; }
namespace G {
const int N = 2333333, M = 6666666;
struct edge {
  int u, v;
  edge(int u0 = 0, int v0 = 0) : u(u0), v(v0) {}
} e[M];
int V, E = 0, V1;
int first[N], next[N];
int cnt = 0, id[N], low[N], topo[N];
int stc = 0, stack[N], top[N];
bool in_stack[N];
int col[N], conflict[N];
inline void addedge(int u, int v) {
  e[++E] = edge(u, v), next[E] = first[u], first[u] = E;
}
inline void implies(int u, int v) {
  addedge(u, v), addedge(((((v)-1) ^ 1) + 1), ((((u)-1) ^ 1) + 1));
}
inline void must(int x) { addedge(((((x)-1) ^ 1) + 1), x); }
void dfs(int x) {
  int i, y;
  id[x] = low[x] = ++cnt, in_stack[x] = true, stack[stc++] = x;
  for (i = first[x]; i; i = next[i])
    if (!id[y = e[i].v])
      dfs(y), down(low[x], low[y]);
    else if (in_stack[y])
      down(low[x], id[y]);
  if (id[x] == low[x]) {
    for (y = 0; y != x; y = stack[--stc], in_stack[y] = false, top[y] = x)
      ;
    topo[V1++] = x;
  }
}
inline bool _2_SAT() {
  int i, u, v;
  cnt = stc = 0;
  for (i = 1; i <= V; ++i)
    if (!id[i]) dfs(i);
  for (i = 1; i <= V; i += 2) {
    if ((u = top[i]) == (v = top[i + 1])) return false;
    conflict[u] = v, conflict[v] = u;
  }
  for (i = 0; i < V1; ++i)
    if (!col[v = topo[i]]) col[v] = 1, col[conflict[v]] = -1;
  for (i = 1; i <= V; ++i) col[i] = col[top[i]];
  return true;
}
}  // namespace G
namespace ST {
struct node {
  int p, lc, rc, L, R;
} x[M];
std::vector<int> ps[M];
int cnt = 0;
int build(int L, int R) {
  int id = ++cnt;
  x[id].L = L, x[id].R = R;
  if (L == R) return id;
  int M = (L + R - 1) >> 1;
  x[id].lc = build(L, M), x[id].rc = build(M + 1, R);
  G::implies((2 * (x[id].lc) - 1), (2 * (id)-1));
  G::implies((2 * (x[id].rc) - 1), (2 * (id)-1));
  return x[id].lc[x].p = x[id].rc[x].p = id;
}
void locate(int id, int L, int R, int ql, int qr, int vertex) {
  if (ql <= L && R <= qr) {
    if (x[id].p) G::implies(vertex, (2 * (x[id].p) - 1));
    ps[id].emplace_back(vertex);
    return;
  }
  int M = (L + R - 1) >> 1;
  if (ql <= M) locate(x[id].lc, L, M, ql, qr, vertex);
  if (qr > M) locate(x[id].rc, M + 1, R, ql, qr, vertex);
}
void relink() {
  int i, j, l, L, R;
  for (i = 1; i <= cnt; ++i)
    if ((l = ps[i].size())) {
      G::implies((2 * (i)-1), (2 * (V + 1) - 1));
      for (j = 1; j < l; ++j)
        G::implies((2 * (V + j) - 1), (2 * (V + j + 1) - 1)),
            G::implies(ps[i][j - 1], (2 * (V + j + 1) - 1));
      for (j = 0; j < l; ++j)
        G::implies((2 * (V + j + 1) - 1), ((((ps[i][j]) - 1) ^ 1) + 1));
      L = x[i].L, R = x[i].R, assert(L[o][top] == R[o][top]);
      if (dak[L]) G::implies((2 * (V + 1)), (2 * (dak[L]) - 1));
      V += l;
    }
}
}  // namespace ST
inline void addedge(int u, int v) {
  to[++E] = v, next[E] = first[u], first[u] = E;
  to[++E] = u, next[E] = first[v], first[v] = E;
}
void dfs(int x) {
  int i, y, &z = prf[x];
  size[x] = !next[first[x]];
  for (i = first[x]; i; i = next[i])
    if ((y = to[i]) != p[x])
      p[y] = x, dep[y] = dep[x] + 1, dfs(y), size[x] += size[y],
      size[y] > size[z] ? z = y : 0;
}
void dfs_hld(int x, int r) {
  int i, y;
  o[++cnt] = x, id[x] = cnt, top[x] = r;
  if (!prf[x]) {
    len[r] = id[x] - id[r] + 1;
    return;
  }
  dfs_hld(prf[x], r);
  for (i = first[x]; i; i = next[i])
    if (!top[y = to[i]]) dfs_hld(y, y);
}
void solve(int u, int v, int vertex) {
  int x = top[u], y = top[v];
  for (; x != y; u = p[x], x = top[u]) {
    if (dep[x] < dep[y]) std::swap(u, v), std::swap(x, y);
    mc[u].emplace_back(vertex);
  }
  if (dep[u] > dep[v]) std::swap(u, v);
  if (u != v) ST::locate(1, 2, n, id[u] + 1, id[v], vertex);
}
int main() {
  int i, j, k, u, v, uu, vv, top;
  scanf("%d", &n);
  for (i = 1; i < n; ++i) scanf("%d%d", &u, &v), addedge(u, v);
  dfs(1), dfs_hld(1, 1);
  ST::build(2, n), assert(ST::cnt == 2 * n - 3);
  scanf("%d", &m), V = 2 * n + m - 3;
  for (i = 0; i < m; ++i) {
    scanf("%d%d%d%d", &u, &v, &uu, &vv), solve(u, v, (2 * (2 * n - 2 + i) - 1));
    solve(uu, vv, (2 * (2 * n - 2 + i)));
  }
  for (i = 1; i <= n; i = j + 1) {
    v = o[i], j = i + len[v] - 1, top = 0;
    for (k = i; k <= j; ++k) {
      dak[k] = V + top + 1;
      for (int x : mc[o[k]]) tmp[top++] = x;
    }
    for (k = 1; k < top; ++k)
      G::implies((2 * (V + k) - 1), (2 * (V + k + 1) - 1)),
          G::implies(tmp[k - 1], (2 * (V + k + 1) - 1));
    for (k = 0; k < top; ++k)
      G::implies((2 * (V + k + 1) - 1), ((((tmp[k]) - 1) ^ 1) + 1));
    V += top;
    for (k = i; k <= j; ++k)
      if (dak[k] > V) dak[k] = 0;
  }
  ST::relink(), G::V = 2 * V;
  if (G::_2_SAT())
    for (puts("YES"), i = 0; i < m; ++i)
      putchar(G::col[(2 * (2 * n - 2 + i) - 1)] == 1 ? 49 : 50), putchar(10);
  else
    puts("NO");
  return 0;
}