Please subscribe to the official Codeforces channel in Telegram via the link: https://t.me/codeforces_official.
×

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

D. Ants

time limit per test

3 secondsmemory limit per test

768 megabytesinput

standard inputoutput

standard outputThere 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 \leq n \leq 10^5$$$) — the number of vertices.

Each of the next $$$n-1$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$), meaning that there is an edge between vertices $$$u_i$$$ and $$$v_i$$$.

The next line contains a single integer $$$m$$$ ($$$1 \leq m \leq 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 \leq a_i, b_i, c_i, d_i \leq n$$$, $$$a_i \neq b_i, c_i \neq 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.

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/12/2018 00:33:15 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|