#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s;
}
const int N = 1e5 + 5, M = 5e6 + 5;
int n, m;
vector<int> G[N];
int dfn[N], top[N], siz[N], fa[N], dep[N], son[N], dfn_t;
int tot;
struct Sat {
  vector<int> G[M];
  int dfn[M], low[M], bel[M], t;
  int stk[M], top, cnt;
  bool instk[M];
  inline void add(int x, int y) {
    G[x].push_back(y);
    G[y ^ 1].push_back(x ^ 1);
  }
  void tarjan(int u) {
    dfn[u] = low[u] = ++t;
    stk[++top] = u;
    instk[u] = 1;
    for (int v : G[u]) {
      if (!dfn[v])
        tarjan(v), low[u] = min(low[u], low[v]);
      else if (instk[v])
        low[u] = min(low[u], dfn[v]);
    }
    if (dfn[u] == low[u]) {
      bel[u] = ++cnt;
      instk[u] = 0;
      while (stk[top] != u) {
        bel[stk[top]] = cnt;
        instk[stk[top--]] = 0;
      }
      top--;
    }
  }
  void solve() {
    for (int i = tot * 2; i >= 1; i--)
      if (!bel[i]) tarjan(i);
    for (int i = 1; i <= m; i++)
      if (bel[i * 2] == bel[i * 2 + 1]) {
        puts("NO");
        return;
      }
    puts("YES");
    for (int i = 1; i <= m; i++)
      if (bel[i * 2] < bel[i * 2 + 1])
        puts("1");
      else
        puts("2");
  }
} T;
void dfs1(int u, int f) {
  siz[u] = 1, dep[u] = dep[f] + 1, fa[u] = f;
  for (int v : G[u]) {
    if (v == f) continue;
    dfs1(v, u);
    siz[u] += siz[v];
    if (siz[v] > siz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int k) {
  top[u] = k;
  dfn[u] = ++dfn_t;
  if (!son[u]) return;
  dfs2(son[u], k);
  for (int v : G[u])
    if (v != fa[u] && v != son[u]) dfs2(v, v);
}
vector<int> vec[N << 2];
inline void update(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    vec[rt].push_back(v);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) update(rt << 1, l, mid, L, R, v);
  if (R > mid) update(rt << 1 | 1, mid + 1, r, L, R, v);
}
inline void modify(int u, int v, int w) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    update(1, 2, n, dfn[top[u]], dfn[u], w);
    u = fa[top[u]];
  }
  if (u != v) {
    if (dep[u] > dep[v]) swap(u, v);
    update(1, 2, n, dfn[u] + 1, dfn[v], w);
  }
}
void build(int rt, int l, int r, int p) {
  int u = ++tot, v = tot + vec[rt].size();
  tot += vec[rt].size();
  if (vec[rt].size())
    T.add((v - 1) * 2, v * 2);
  else if (p)
    T.add(p * 2, v * 2);
  for (int i = 0; i < vec[rt].size(); i++) {
    int j = vec[rt][i];
    T.add(j, (u + i) * 2);
    if (i > 0)
      T.add((u + i - 1) * 2, (u + i) * 2), T.add((u + i - 1) * 2, j ^ 1);
    else if (p)
      T.add(p * 2, u * 2), T.add(p * 2, j ^ 1);
  }
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid, v);
  build(rt << 1 | 1, mid + 1, r, v);
}
int main() {
  n = read();
  for (int i = 1; i < n; i++) {
    int u = read(), v = read();
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) reverse(G[i].begin(), G[i].end());
  dfs1(1, 0);
  dfs2(1, 1);
  m = read();
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read();
    modify(u, v, i * 2);
    u = read(), v = read();
    modify(u, v, i * 2 + 1);
  }
  tot = m;
  build(1, 2, n, 0);
  T.solve();
  return 0;
}
