'Wishing Snake' is a computer game for children. In this game, there is a board and a snake. The board contains 1000 checkpoints numbered from 0 to 999. Initially, the snake sits at checkpoint 0.
Now n children come in front of the board and start wishing. Each wish looks like - "I want to see the snake walking from checkpoint u to checkpoint v." Each child can have multiple wishes. At first, a child comes in front of the board and makes his/her wishes. After that, a new child comes and makes his new wishes (that means not wished by any children yet). And it continues until the nth children.
After that, the snake starts walking from one checkpoint to another. It can only walk from one checkpoint to another if any child had wished it. While walking from checkpoint u to checkpoint v, the snake cannot cross any other checkpoints along the path.
The snake wants to fulfill all the wishes done by all the children in one single path. Since you are the lead designer of the game, you want to find whether it's possible or not.
Input
Input starts with an integer T (≤ 65), denoting the number of test cases.
Each case starts with an integer n (1 ≤ n ≤ 100). Then for each child an integer k (k ≥ 0) is given. Each of the next k lines contains two integers u v (0 ≤ u, v < 1000, u ≠ v) denoting that the child wants to see the snake going from checkpoint u to checkpoint v. You may assume that all the wishes are distinct and correct. And the total number of wishes in any case is between 1 and 10000 (inclusive).
Output
For each case, print the case number and YES
if it's possible, otherwise print NO
.
Sample
Sample Input | Sample Output |
---|---|
2 2 2 0 9 9 10 1 10 15 1 2 0 9 0 11 | Case 1: YES Case 2: NO |