#include <bits/stdc++.h>
using namespace std;
const int P = 1 << 23, Q = 1 << 19;
int inc = 0;
int las[P], e[P], nn[P];
void ins(int x, int y) {
  e[++inc] = y;
  nn[inc] = las[x];
  las[x] = inc;
}
void sss(int x, int y) { ins(x, y), ins(y ^ 1, x ^ 1); }
int ls[Q], rs[Q], tot;
vector<int> E[1 << 17], qaq[1 << 18];
void LINK(int x, int y) {
  E[x].push_back(y);
  E[y].push_back(x);
}
void MT(int &now, int l, int r) {
  now = ++tot;
  if (l == r) return;
  int mid = (l + r) >> 1;
  MT(ls[now], l, mid);
  MT(rs[now], mid + 1, r);
}
void MDF(int now, int l, int r, int x, int y, int d) {
  if (x <= l && y >= r) {
    qaq[now].push_back(d);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) MDF(ls[now], l, mid, x, y, d);
  if (y > mid) MDF(rs[now], mid + 1, r, x, y, d);
}
int si[Q], bs[Q], dep[Q], fa[Q], top[Q], id[Q];
void dfs1(int x) {
  int mx = 0;
  si[x] = 1;
  for (int i = 0; i < E[x].size(); i++) {
    int y = E[x][i];
    if (y == fa[x]) continue;
    fa[y] = x;
    dep[y] = dep[x] + 1;
    dfs1(y);
    si[x] += si[y];
    if (si[y] > mx) mx = si[y], bs[x] = y;
  }
}
int Time = 0;
void dfs2(int x, int T) {
  top[x] = T;
  id[x] = ++Time;
  if (bs[x]) dfs2(bs[x], T);
  for (int i = 0; i < E[x].size(); i++) {
    int y = E[x][i];
    if (y == fa[x] || y == bs[x]) continue;
    dfs2(y, y);
  }
}
int n;
int rt = 0;
void MP(int a, int b, int p) {
  while (top[a] != top[b]) {
    if (dep[top[a]] < dep[top[b]]) swap(a, b);
    MDF(rt, 1, n, id[top[a]], id[a], p);
    a = fa[top[a]];
  }
  if (dep[a] > dep[b]) swap(a, b);
  if (a != b) MDF(rt, 1, n, id[a] + 1, id[b], p);
}
int dfn[P], low[P];
int bel[P];
stack<int> st;
int scc = 0;
int inst[P];
void dfs(int x) {
  dfn[x] = low[x] = ++Time;
  inst[x] = 1;
  st.push(x);
  for (int t = las[x]; t; t = nn[t]) {
    int y = e[t];
    if (!dfn[y])
      dfs(y), low[x] = min(low[x], low[y]);
    else if (inst[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] != low[x]) return;
  int now;
  ++scc;
  do {
    now = st.top();
    st.pop();
    inst[now] = 0;
    bel[now] = scc;
  } while (now != x);
}
int tl;
int Reb(int now, int l, int r) {
  int lp = ++tl;
  if (l != r) {
    int mid = (l + r) >> 1;
    int sl = Reb(ls[now], l, mid);
    int sr = Reb(rs[now], mid + 1, r);
    sss(lp << 1 | 1, sl << 1 | 1);
    sss(lp << 1 | 1, sr << 1 | 1);
  }
  for (int i = 0; i < qaq[now].size(); i++) {
    int a = qaq[now][i];
    int ne = ++tl;
    sss(a, ne << 1);
    sss(a, lp << 1 | 1);
    sss(ne << 1 | 1, lp << 1 | 1);
    lp = ne;
  }
  return lp;
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; i++) scanf("%d%d", &x, &y), LINK(x, y);
  dfs1(1);
  dfs2(1, 1);
  Time = 0;
  int m;
  scanf("%d", &m);
  MT(rt, 1, n);
  for (int i = 1; i <= m; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    MP(a, b, i << 1);
    MP(c, d, i << 1 | 1);
  }
  tl = m;
  Reb(rt, 1, n);
  for (int i = 1; i <= m; i++) {
    if (!dfn[i << 1]) dfs(i << 1);
    if (!dfn[i << 1 | 1]) dfs(i << 1 | 1);
  }
  for (int i = 1; i <= m; i++)
    if (bel[i << 1] == bel[i << 1 | 1]) return puts("NO") & 0;
  puts("YES");
  for (int i = 1; i <= m; i++)
    printf("%d\n", bel[i << 1] < bel[i << 1 | 1] ? 1 : 2);
  return 0;
}
