Frogs 2

Assign one frog to each pad so that every frog sits on a preferred pad and each log joins two frogs with equal interest in the log's topic.

Hard8GraphBacktrackingDFSSortingNo attempts yetTime limit1sMemory limit256 MB

Problem

A pond has NN lily pads that frogs can sit on and MM logs that act as bridges between pads. At most one log connects any given pair of pads. NN frogs want to rest, one frog per pad, so after the placement every pad holds exactly 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, philosophy. Every frog has an interest level from 1 to 5 for each topic.

Each log has one fixed topic. The two frogs it joins can talk when their interest levels for that topic are equal, and cannot talk when the levels differ.

Every frog also prefers 1 or 2 pads. A frog placed on a pad it does not prefer gets upset and wrecks the place, so every frog must go to a pad it prefers.

Write a program that decides whether the frogs can be placed so that a conversation happens on every log with that log's topic, and that reports the placement when one exists.

Input

The first line contains NN and MM. (1N1001 \le N \le 100, 0Mmin(N(N1)/2,1000)0 \le M \le \min(N(N-1)/2, 1000))

Each of the next NN lines contains four integers, the interest levels of frogs 1 through NN in food, hobbies, family, and philosophy. Each integer is between 1 and 5.

Each of the next NN lines contains the pad numbers AA and BB preferred by frogs 1 through NN. (1A,BN1 \le A, B \le N) A frog that prefers only one pad is given with A=BA = B.

Each of the next 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 conversation topic is topic TT. The topics are numbered in the order food, hobbies, family, philosophy.

Output

If a valid placement exists, print YES on the first line. On the second line print, separated by spaces, the number of the frog placed on pad 1 through pad NN.

If several placements are valid, only the lexicographically smallest sequence counts as correct. Choose the placement whose frog on pad 1 has the smallest number, break ties by the frog on pad 2, and so on.

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