Frog 3

Assign each frog to a preferred pad so that every pair of pads joined by a log holds frogs with equal interest for that log's topic.

Medium6GraphBacktrackingImplementationBrute forceNo attempts yetTime limit1sMemory limit256 MB

Problem

A pond has NN lotus pads that frogs can sit on and MM logs that join pads and work as bridges. At most one log joins any given pair of pads. NN frogs each want to rest on one pad, and one pad holds one frog.

Two frogs on pads joined by a log must be able to talk, otherwise they quarrel. There are four conversation topics: food, hobbies, family, and philosophy. Every frog has an interest level from 1 to 5 for each topic.

Each log carries one fixed topic. The conversation happens only when the two frogs have the same interest level for that topic.

Each frog also prefers one or two pads. On any other pad it turns unhappy and wrecks the place, so every frog must sit on a pad it prefers.

Write a program that decides whether the frogs can be placed so that every log allows a conversation on its topic, and that reports such a placement when one exists.

Input

The first line contains NN and MM. (1N30001 \le N \le 3000, 0Mmin(N(N1)/2, 5×105)0 \le M \le \min(N(N-1)/2,\ 5 \times 10^5))

Each of the next NN lines contains four integers, the interest levels of one frog for food, hobbies, family, and philosophy in that order. Each integer is between 1 and 5. The ii-th of these lines describes frog ii.

Each of the next NN lines contains the numbers AA and BB of the pads one frog prefers. (1A,BN1 \le A, B \le N) A frog that prefers a single pad is given with A=BA = B. The ii-th of these lines describes frog ii.

Each of the last MM lines contains three integers AA, BB, and TT. (1A,BN1 \le A, B \le N, ABA \ne B, 1T41 \le T \le 4) A log joins pad AA and pad BB, and its topic is topic TT. The topics are numbered in the order food, hobbies, family, philosophy.

Output

If a placement exists, print YES on the first line. On the second line print the number of the frog placed on pad 11, then pad 22, and so on up to pad NN, separated by spaces. When several placements work, print the one whose sequence is lexicographically smallest.

If no placement exists, print NO on the first line.