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 edge {
  int r, nxt;
} e[100100 << 1];
struct data {
  int lc, rc, cnt;
  vector<int> v;
} s[100100 << 2];
int dy[100100], anses[100100], dep[100100], ptr;
int Q[100100], Qsz, bel[100100], idsz, A[100100], Asz;
int ai[100100], rt[100100], bi[100100], ci[100100], di[100100];
int fa[100100], dfn[100100], son[100100];
int n, m, head[100100], top[100100], rig[100100], tim, esz, vis[100100];
void addedge(int u, int v) {
  e[++esz].r = v;
  e[esz].nxt = head[u];
  head[u] = esz;
  e[++esz].r = u;
  e[esz].nxt = head[v];
  head[v] = esz;
}
int dfs1(int u) {
  int sz = 1, s = 0, mxsize = 0;
  for (int t = head[u]; t; t = e[t].nxt)
    if (e[t].r != fa[u]) {
      fa[e[t].r] = u, s = dfs1(e[t].r), sz += s;
      if (mxsize < s) mxsize = s, son[u] = e[t].r;
    }
  return sz;
}
void dfs2(int u, int tp) {
  top[u] = tp, dfn[u] = ++tim, dep[u] = dep[fa[u]] + 1;
  rig[tp] = max(rig[tp], tim);
  if (son[u]) dfs2(son[u], tp);
  for (int t = head[u]; t; t = e[t].nxt)
    if (e[t].r != fa[u] && e[t].r != son[u]) dfs2(e[t].r, e[t].r);
}
void build(int& o, int l, int r) {
  o = ++ptr;
  if (l == r) return;
  int mid = l + r >> 1;
  build(s[o].lc, l, mid);
  build(s[o].rc, mid + 1, r);
}
void ins(int o, int l, int r, int ql, int qr, int id, int flg) {
  if (ql > qr) return;
  s[o].cnt += flg;
  if (ql <= l && r <= qr) {
    if (flg == 1) s[o].v.push_back(id);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) ins(s[o].lc, l, mid, ql, qr, id, flg);
  if (qr > mid) ins(s[o].rc, mid + 1, r, ql, qr, id, flg);
}
void instree(int u, int v, int id, int flg) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    ins(rt[top[u]], dfn[top[u]], rig[top[u]], dfn[top[u]], dfn[u], id, flg);
    u = fa[top[u]];
  }
  if (dfn[u] > dfn[v]) swap(u, v);
  ins(rt[top[u]], dfn[top[u]], rig[top[u]], dfn[u] + 1, dfn[v], id, flg);
}
void init(int flg) {
  for (int i = 1; i <= ptr; ++i) s[i].v.clear(), s[i].cnt = 0;
  for (int i = 1; i <= m; ++i) {
    if (flg == 0) {
      instree(ai[i], bi[i], ((i)*2 + (1)), 1);
      instree(ci[i], di[i], ((i)*2 + (0)), 1);
    } else {
      instree(ai[i], bi[i], ((i)*2 + (0)), 1);
      instree(ci[i], di[i], ((i)*2 + (1)), 1);
    }
  }
}
int qry(int o, int l, int r, int ql, int qr) {
  if (!s[o].cnt) return -1;
  if (ql > qr) return -1;
  while (s[o].v.size()) {
    int x = s[o].v.back();
    if (!vis[x])
      return x;
    else
      s[o].v.pop_back();
  }
  int mid = l + r >> 1, ret = -1;
  if (ql <= mid) ret = qry(s[o].lc, l, mid, ql, qr);
  if (qr > mid && ret == -1) ret = qry(s[o].rc, mid + 1, r, ql, qr);
  return ret;
}
int qtree(int fr, int flg) {
  int u, v;
  if (fr % 2 == flg)
    u = ai[fr >> 1], v = bi[fr >> 1];
  else
    u = ci[fr >> 1], v = di[fr >> 1];
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    int x = qry(rt[top[u]], dfn[top[u]], rig[top[u]], dfn[top[u]], dfn[u]);
    if (x != -1) return x;
    u = fa[top[u]];
  }
  if (dfn[u] > dfn[v]) swap(u, v);
  int x = qry(rt[top[u]], dfn[top[u]], rig[top[u]], dfn[u] + 1, dfn[v]);
  return x;
}
void era(int fr, int flg) {
  vis[fr] = 1;
  int u, v;
  if (fr % 2 == !flg)
    u = ai[fr >> 1], v = bi[fr >> 1];
  else
    u = ci[fr >> 1], v = di[fr >> 1];
  instree(u, v, fr, -1);
}
void _ins(int fr, int flg) {
  vis[fr] = 0;
  int u, v;
  if (fr % 2 == !flg)
    u = ai[fr >> 1], v = bi[fr >> 1];
  else
    u = ci[fr >> 1], v = di[fr >> 1];
  instree(u, v, fr, 1);
}
void dfs(int u, int flg = 0) {
  if (flg == 1) bel[u] = idsz, A[++Asz] = u;
  vis[u] = 1, era(u, flg);
  while (true) {
    if (vis[u ^ 1]) {
      int nxt = qtree(u, flg);
      if (nxt != -1)
        dfs(nxt, flg);
      else
        break;
    } else {
      era(u ^ 1, flg);
      int nxt = qtree(u, flg);
      _ins(u ^ 1, flg);
      if (nxt != -1)
        dfs(nxt, flg);
      else
        break;
    }
  }
  if (flg == 0) Q[++Qsz] = u;
}
int main() {
  scanf("%d", &n);
  for (int i = 2, u, v; i <= n; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d%d", &ai[i], &bi[i], &ci[i], &di[i]);
  dfs1(1), dfs2(1, 1);
  for (int i = 1; i <= n; ++i)
    if (top[i] == i) build(rt[i], dfn[i], rig[i]);
  init(0);
  for (int i = ((1) * 2 + (0)); i <= ((m)*2 + (1)); ++i)
    if (!vis[i]) dfs(i);
  init(1);
  memset(vis, 0, sizeof(vis));
  for (int i = Qsz; i >= 1; --i)
    if (!vis[Q[i]]) ++idsz, dfs(Q[i], 1);
  for (int i = 1; i <= m; ++i)
    if (bel[((i)*2 + (0))] == bel[((i)*2 + (1))]) return puts("NO"), 0;
  puts("YES");
  for (int i = Asz; i >= 1; --i)
    if (!dy[A[i]]) {
      dy[A[i]] = dy[A[i] ^ 1] = 1;
      anses[A[i] >> 1] = (A[i] % 2 == 0 ? 1 : 2);
    }
  for (int i = 1; i <= m; ++i) printf("%d\n", anses[i]);
}