#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  T x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f = c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
namespace run {
const int N = 4e5 + 9;
int head[N], nex[N], to[N], cnt;
inline void add(int u, int v) {
  nex[++cnt] = head[u];
  head[u] = cnt, to[cnt] = v;
}
int siz[N], son[N], dep[N], fa[N];
inline void dfs1(int u, int _f) {
  siz[u] = 1, dep[u] = dep[_f] + 1, fa[u] = _f;
  for (int i = head[u]; i; i = nex[i]) {
    if (to[i] ^ _f) {
      dfs1(to[i], u), siz[u] += siz[to[i]];
      if (siz[to[i]] > siz[son[u]]) son[u] = to[i];
    }
  }
}
int dfn[N], num, rak[N], top[N];
inline void dfs2(int u, int tp) {
  rak[dfn[u] = ++num] = u, top[u] = tp;
  if (son[u]) dfs2(son[u], tp);
  for (int i = head[u]; i; i = nex[i])
    if (!dfn[to[i]]) dfs2(to[i], to[i]);
}
namespace Tar {
int head[N << 2], nex[N * 20], to[N * 20], cnt;
inline void add(int u, int v) {
  nex[++cnt] = head[u];
  assert(cnt < N * 20);
  head[u] = cnt, to[cnt] = v;
}
int dfn[N << 2], low[N << 2], ins[N << 2], num, bel[N << 2], col_cnt;
stack<int> S;
inline void tarjan(int u) {
  dfn[u] = low[u] = ++num, ins[u] = 1, S.push(u);
  for (int i = head[u]; i; i = nex[i]) {
    if (!dfn[to[i]]) {
      tarjan(to[i]);
      low[u] = min(low[u], low[to[i]]);
    } else if (ins[to[i]])
      low[u] = min(low[u], dfn[to[i]]);
  }
  if (dfn[u] == low[u]) {
    int y;
    col_cnt++;
    do {
      y = S.top();
      S.pop();
      bel[y] = col_cnt, ins[y] = 0;
    } while (y != u);
  }
}
}  // namespace Tar
int n, m;
namespace Seg {
int tot;
vector<int> d[N << 2];
inline void modify(int k, int l, int r, int _l, int _r, int v) {
  if (_l <= l && r <= _r) return d[k].push_back(v), void();
  if (_l <= ((l + r) >> 1)) modify((k << 1), l, ((l + r) >> 1), _l, _r, v);
  if (_r > ((l + r) >> 1))
    modify((k << 1 | 1), ((l + r) >> 1) + 1, r, _l, _r, v);
}
inline void build(int k, int l, int r, int las0, int las1, int las2) {
  for (int i = 0; i < d[k].size(); i++) {
    int tmp0 = ++tot, tmp1 = ++tot, p = d[k][i] > m ? d[k][i] - m : d[k][i] + m;
    Tar::add(d[k][i], tmp0), Tar::add(d[k][i], tmp1);
    if (las0) Tar::add(las0, tmp0), Tar::add(las0, p);
    if (las1) Tar::add(tmp1, las1);
    if (las2) Tar::add(tmp1, las2);
    las0 = tmp0, las1 = tmp1, las2 = p;
  }
  if (l == r) return;
  build((k << 1), l, ((l + r) >> 1), las0, las1, las2);
  build((k << 1 | 1), ((l + r) >> 1) + 1, r, las0, las1, las2);
}
}  // namespace Seg
inline void modify(int u, int v, int id) {
  while (top[u] ^ top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    Seg::modify(1, 1, n, dfn[top[u]], dfn[u], id);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) swap(u, v);
  if (v ^ u) Seg::modify(1, 1, n, dfn[v] + 1, dfn[u], id);
}
int main() {
  n = read<int>();
  for (int i = 1; i < n; i++) {
    int u = read<int>(), v = read<int>();
    add(u, v), add(v, u);
  }
  dfs1(1, 0), dfs2(1, 0);
  m = read<int>(), Seg::tot = 2 * m;
  for (int i = 1; i <= m; i++) {
    int u = read<int>(), v = read<int>();
    modify(u, v, i);
    u = read<int>(), v = read<int>();
    modify(u, v, i + m);
  }
  Seg::tot = 2 * m, Seg::build(1, 1, n, 0, 0, 0);
  for (int i = 1; i <= 2 * m; i++)
    if (!Tar::dfn[i]) Tar::tarjan(i);
  for (int i = 1; i <= m; i++)
    if (Tar::bel[i] == Tar::bel[i + m]) return puts("NO"), 0;
  puts("YES");
  for (int i = 1; i <= m; i++)
    if (Tar::bel[i] < Tar::bel[i + m])
      puts("1");
    else
      puts("2");
  return 0;
}
}  // namespace run
int main() { return run::main(); }
