#include <bits/stdc++.h>
using namespace std;
const int maxn = 9000000 + 5;
const int maxq = 5e5 + 5;
int en[maxq], nt[maxq], la[maxq], owo;
void adg(int x, int y) {
  en[++owo] = y;
  nt[owo] = la[x];
  la[x] = owo;
}
int LA[maxn], EN[maxn], NT[maxn], OWO;
void ADG(int X, int Y) {
  EN[++OWO] = Y;
  NT[OWO] = LA[X];
  LA[X] = OWO;
}
int ls[maxq], rs[maxq], segtot, rt;
int n, m, tot, IN[maxq], OUT[maxq], dfx, zerz[maxq], siz[maxq];
int dep[maxq], fa[maxq], top[maxq];
vector<int> oyo[maxq];
void ins(int x, int y) {
  ADG(x, y);
  ADG(y ^ 1, x ^ 1);
}
void dfs1(int x, int ba) {
  dep[x] = dep[ba] + 1;
  fa[x] = ba;
  siz[x] = 1;
  for (int it = la[x]; it; it = nt[it]) {
    int y = en[it];
    if (y == ba) continue;
    dfs1(y, x);
    siz[x] += siz[y];
    if (siz[zerz[x]] < siz[y]) zerz[x] = y;
  }
}
void dfs2(int x, int ace) {
  top[x] = ace;
  IN[x] = ++dfx;
  if (zerz[x]) dfs2(zerz[x], ace);
  for (int it = la[x]; it; it = nt[it]) {
    int y = en[it];
    if (y == fa[x] || y == zerz[x]) continue;
    dfs2(y, y);
  }
  OUT[x] = dfx;
}
void change(int &p, int l, int r, int x, int y, int o) {
  if (x <= l && r <= y) {
    oyo[p].push_back(o);
    return;
  }
  int mid = (l + r) >> 1;
  if (y <= mid)
    change(ls[p], l, mid, x, y, o);
  else if (x > mid)
    change(rs[p], mid + 1, r, x, y, o);
  else
    change(ls[p], l, mid, x, y, o), change(rs[p], mid + 1, r, x, y, o);
}
void modify(int x, int y, int o) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    change(rt, 1, n, IN[top[x]], IN[x], o);
    x = fa[top[x]];
  }
  if (dep[x] > dep[y]) swap(x, y);
  if (x != y) change(rt, 1, n, IN[x] + 1, IN[y], o);
}
void maketree(int &p, int l, int r) {
  p = ++segtot;
  if (l == r) return;
  int mid = (l + r) >> 1;
  maketree(ls[p], l, mid);
  maketree(rs[p], mid + 1, r);
}
int GAO(int p, int l, int r) {
  int now = ++tot;
  if (l < r) {
    int mid = (l + r) >> 1;
    int rul = GAO(ls[p], l, mid);
    int rur = GAO(rs[p], mid + 1, r);
    ins(now * 2 + 1, rul * 2 + 1);
    ins(now * 2 + 1, rur * 2 + 1);
  }
  int net;
  for (auto o : oyo[p]) {
    net = ++tot;
    ins(o, now * 2 + 1);
    ins(net * 2 + 1, now * 2 + 1);
    ins(o, net * 2);
    now = net;
  }
  return now;
}
int dfn[maxn], low[maxn], tjdfx, sta[maxn], tp, ID[maxn], scc;
bool inst[maxn];
void tarjan(int x) {
  low[x] = dfn[x] = ++tjdfx;
  sta[++tp] = x;
  inst[x] = 1;
  for (int it = LA[x]; it; it = NT[it]) {
    int y = EN[it];
    if (!dfn[y]) {
      tarjan(y);
      low[x] = min(low[x], low[y]);
    } else if (inst[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    int y;
    ++scc;
    do {
      y = sta[tp--];
      ID[y] = scc;
      inst[y] = 0;
    } while (y != x);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    adg(x, y);
    adg(y, x);
  }
  scanf("%d", &m);
  tot = m;
  maketree(rt, 1, n);
  dfs1(1, 0);
  dfs2(1, 1);
  for (int i = 1; i <= m; i++) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    modify(a, b, i * 2);
    modify(c, d, i * 2 + 1);
  }
  GAO(rt, 1, n);
  for (int i = 2; i <= m * 2 + 1; i++) {
    if (!dfn[i]) tarjan(i);
  }
  for (int i = 1; i <= m; i++) {
    if (ID[2 * i] == ID[2 * i + 1]) {
      puts("NO");
      return 0;
    }
  }
  puts("YES");
  for (int i = 1; i <= m; i++) {
    if (ID[i * 2] < ID[i * 2 + 1])
      puts("1");
    else
      puts("2");
  }
}
