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 Tree {
  const int LOW = -1234567890;
  int f(int a, int b) { return max(a, b); }
  int n;
  vector<int> s;
  vector<vector<int> > stuff;
  Tree() {}
  Tree(int m, int def = 0) { init(m, def); }
  void init(int m, int def) {
    n = 1;
    while (n < m) n *= 2;
    s.assign(n + m, def);
    s.resize(2 * n, LOW);
    stuff.resize(2 * n);
    for (int i = n; i-- > 1;) s[i] = f(s[i * 2], s[i * 2 + 1]);
  }
  void update(int pos, int val) {
    pos += n;
    s[pos] = val;
    for (pos /= 2; pos >= 1; pos /= 2) s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
  }
  int query(int l, int r, int id) { return que(1, l, r, 0, n, id); }
  int que(int pos, int l, int r, int lo, int hi, int id) {
    if (r <= lo || hi <= l) return LOW;
    if (l <= lo && hi <= r) {
      stuff[pos].push_back(id);
      return s[pos];
    }
    int m = (lo + hi) / 2;
    return f(que(2 * pos, l, r, lo, m, id), que(2 * pos + 1, l, r, m, hi, id));
  }
};
struct Node {
  int d, par, val, chain = -1, pos = -1;
  vector<int> stuff;
};
struct Chain {
  int par, val;
  vector<int> nodes;
  Tree tree;
};
struct HLD {
  const int LOW = -(1 << 29);
  void f(int& a, int b) { a = max(a, b); }
  vector<Node> V;
  vector<Chain> C;
  HLD(vector<vector<pair<int, int> > >& g) : V((int)(g).size()) {
    dfs(0, -1, g, 0);
    for (auto& c : C) {
      c.tree.init((int)(c.nodes).size(), 0);
      for (int ni : c.nodes) c.tree.update(V[ni].pos, V[ni].val);
    }
  }
  void update(int node, int val) {
    Node& n = V[node];
    n.val = val;
    if (n.chain != -1) C[n.chain].tree.update(n.pos, val);
  }
  int pard(Node& nod) {
    if (nod.par == -1) return -1;
    return V[nod.chain == -1 ? nod.par : C[nod.chain].par].d;
  }
  pair<int, int> query(int i1, int i2, int id) {
    int ans = LOW;
    while (i1 != i2) {
      Node n1 = V[i1], n2 = V[i2];
      if (n1.chain != -1 && n1.chain == n2.chain) {
        int lo = n1.pos, hi = n2.pos;
        if (lo > hi) swap(lo, hi);
        f(ans, C[n1.chain].tree.query(lo, hi, id));
        i1 = i2 = C[n1.chain].nodes[hi];
      } else {
        if (pard(n1) < pard(n2)) n1 = n2, swap(i1, i2);
        if (n1.chain == -1) {
          f(ans, n1.val);
          V[i1].stuff.push_back(id);
          i1 = n1.par;
        } else {
          Chain& c = C[n1.chain];
          if (n1.pos) {
            f(ans, c.tree.query(n1.pos, (int)(c.nodes).size(), id));
          } else {
            f(ans, c.tree.s[1]);
            c.tree.stuff[1].push_back(id);
          }
          i1 = c.par;
        }
      }
    }
    return make_pair(ans, i1);
  }
  pair<int, int> dfs(int at, int par, vector<vector<pair<int, int> > >& g,
                     int d) {
    V[at].d = d;
    V[at].par = par;
    int sum = 1, ch, nod, sz;
    tuple<int, int, int> mx(-1, -1, -1);
    for (auto& e : g[at]) {
      if (e.first == par) continue;
      tie(sz, ch) = dfs(e.first, at, g, d + 1);
      V[e.first].val = e.second;
      sum += sz;
      mx = max(mx, make_tuple(sz, e.first, ch));
    }
    tie(sz, nod, ch) = mx;
    if (2 * sz < sum) return pair<int, int>(sum, -1);
    if (ch == -1) {
      ch = (int)(C).size();
      C.emplace_back();
    }
    V[nod].pos = (int)(C[ch].nodes).size();
    V[nod].chain = ch;
    C[ch].par = at;
    C[ch].nodes.push_back(nod);
    return pair<int, int>(sum, ch);
  }
};
struct TwoSat {
  int N;
  vector<vector<int> > gr;
  vector<int> values;
  TwoSat(int n = 0) : N(n), gr(2 * n) {}
  int add_var() {
    gr.emplace_back();
    gr.emplace_back();
    return N++;
  }
  void either(int f, int j) {
    f = max(2 * f, -1 - 2 * f);
    j = max(2 * j, -1 - 2 * j);
    gr[f ^ 1].push_back(j);
    gr[j ^ 1].push_back(f);
  }
  void set_value(int x) { either(x, x); }
  void at_most_one(const vector<int>& li) {
    if ((int)(li).size() <= 1) return;
    int cur = ~li[0];
    for (int i = 2; i < ((int)(li).size()); ++i) {
      int next = add_var();
      either(cur, ~li[i]);
      either(cur, next);
      either(~li[i], next);
      cur = ~next;
    }
    either(cur, ~li[1]);
  }
  vector<int> val, comp, z;
  int time = 0;
  int dfs(int i) {
    int low = val[i] = ++time, x;
    z.push_back(i);
    for (auto& e : gr[i])
      if (!comp[e]) low = min(low, val[e] ?: dfs(e));
    ++time;
    if (low == val[i]) do {
        x = z.back();
        z.pop_back();
        comp[x] = time;
        if (values[x >> 1] == -1) values[x >> 1] = !(x & 1);
      } while (x != i);
    return val[i] = low;
  }
  bool solve() {
    values.assign(N, -1);
    val.assign(2 * N, 0);
    comp = val;
    for (int i = 0; i < (2 * N); ++i)
      if (!comp[i]) dfs(i);
    for (int i = 0; i < (N); ++i)
      if (comp[2 * i] == comp[2 * i + 1]) return 0;
    return 1;
  }
};
int dostuff(TwoSat& ts, Tree& t, int id) {
  int z = ts.add_var();
  if (id >= t.s.size()) {
    return z;
  } else {
    ts.at_most_one(t.stuff[id]);
    int uses = ts.add_var();
    for (int q : t.stuff[id]) {
      ts.either(~q, uses);
    }
    int lz = dostuff(ts, t, 2 * id);
    int rz = dostuff(ts, t, 2 * id + 1);
    ts.either(~uses, ~lz);
    ts.either(~uses, ~rz);
    ts.either(~uses, z);
    ts.either(~lz, z);
    ts.either(~rz, z);
    return z;
  }
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > graph(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back({b, 0});
    graph[b].push_back({a, 0});
  }
  int m;
  cin >> m;
  HLD hld(graph);
  for (int i = 0; i < m; i++) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    hld.query(a, b, i);
    hld.query(c, d, ~i);
  }
  TwoSat ts(m);
  for (Node& v : hld.V) {
    ts.at_most_one(v.stuff);
  }
  for (Chain& c : hld.C) {
    dostuff(ts, c.tree, 1);
  }
  if (ts.solve()) {
    cout << "YES" << '\n';
    for (int i = 0; i < m; i++) {
      int r = 2 - ts.values[i];
      cout << r << '\n';
    }
  } else {
    cout << "NO" << '\n';
  }
}