The Postman

No attempts yetTime limit1sMemory limit128 MB

Problem

Every morning Byteasar the postman must travel through every street of his district to deliver the mail. All roads are one-way and connect the crossroads, which are numbered from 11 to nn. Any two crossroads are joined by at most two roads, one in each direction.

Byteasar starts and finishes every route at the post office, located at crossroad 11. He used to choose his routes himself, but a new regulation now limits that freedom. He is assigned a collection of route fragments: several sequences of crossroad numbers. Byteasar must pick a route that

  • travels along every street exactly once,
  • contains each assigned sequence as a run of consecutive crossroads (that is, the sequence appears as consecutive entries vi,vi+1,v_i, v_{i+1}, \dots of the route),
  • starts and ends at crossroad 11.

It may happen that no route satisfies all of these requirements (for instance, an assigned sequence may require a road that does not exist). Decide only whether such a route exists.

Input

The first line contains two integers nn and mm (2n500002 \le n \le 50000, 1m2000001 \le m \le 200000), the number of crossroads and the number of roads.

Each of the next mm lines contains two integers aa and bb (1a,bn1 \le a, b \le n, aba \ne b), describing a one-way road from crossroad aa to crossroad bb. Each ordered pair (a,b)(a, b) appears at most once.

The next line contains an integer tt (0t100000 \le t \le 10000), the number of assigned sequences. Each of the next tt lines describes one sequence: an integer kk (2k2000002 \le k \le 200000) followed by kk crossroad numbers. The total length of all sequences does not exceed 10000001000000.

Output

Print a single line:

  • TAK if a route satisfying all requirements exists,
  • NIE if no such route exists.

(TAK and NIE mean "yes" and "no" in Polish.)

Hint