Legends

Given a connected graph, decide whether it can be built from one of five small starting graphs using edge additions, isolated-vertex additions, and vertex splits (each split adds a new vertex adjacent to the old one).

Hard9GraphDivide and conquerRecursionImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

The country of Canadia consists of cities and roads. Each road can be traversed in both directions, and it is possible to get from any city to any other city using the roads.

Suzie studies the creation myths of the Canadiaan people. She is particularly interested in five myths, which correspond to the five subtasks of this problem. The myths are very similar. Each myth has the following form.

In the beginning, Canadia's road network had a particular structure. As time went on, the network was modified to meet the needs of Canadia's growing population. Each modification had one of the following forms:

  • A road was built between two cities that did not yet have a road going directly between them.
  • A new city was built. A city built this way is not initially connected to any existing city.
  • A city uu grew too large and was split into two cities vv and ww. The cities originally joined directly to uu by a road are partitioned into sets AA and BB. A road is built from each city in AA to vv, from each city in BB to ww, and from vv to ww.

For example, the city in the center of is split, and the network becomes .

The five myths differ only in the structure that they believe Canadia began with. The original structures according to each myth are as follows.

Subtask and mythPictureOriginal structure
1. The Myth of the Flask4 cities a,b,c,da, b, c, d and 5 roads aa-bb, aa-cc, bb-cc, aa-dd, bb-dd (every pair of cities is joined except cc and dd)
2. The Myth of the Moon3 cities joined in a cycle by 3 roads (a triangle)
3. The Myth of the Sun4 cities joined in a cycle by 4 roads
4. The Myth of the Eagle's Talon1 city joined to each of 3 other cities (4 cities, 3 roads)
5. The Myth of the Fox5 cities a,b,c,d,ea, b, c, d, e and 5 roads aa-bb, bb-cc, cc-aa, aa-dd, bb-ee (a triangle with one extra city attached to each of two of its corners)

For each subtask, you are given the current layout of Canadia and must determine whether the myth might be correct, that is, whether some sequence of the modifications above (possibly empty) turns the myth's original structure into exactly the given layout, with city numbers disregarded.

Input

The first line contains a single integer SS (1S51 \le S \le 5), the subtask to solve. The second line contains an integer TT (1T1 \le T), the number of test cases.

Each test case consists of a blank line, followed by a line with two integers NN and MM (2N2 \le N, 1M1 \le M), the number of cities and roads. The cities are numbered from 11 to NN. Then MM lines follow, each containing two integers aa and bb (1a,bN1 \le a, b \le N), meaning that cities aa and bb are connected by a road. No road connects a city to itself, and no two roads connect the same pair of cities. It is possible to get from any city to any other city using the roads.

In subtask 3, the sum of NN over all test cases is at most 10510^5, and the sum of MM over all test cases is at most 10510^5. In all other subtasks, the sum of NN over all test cases is at most 10001000, and the sum of MM over all test cases is at most 10001000.

Output

For each test case, output a single line containing YES if the myth might be correct, or NO otherwise.