Rock Paper Scissors Strategy

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Yunee, the president of UNIST Rock-Paper-Scissors Association, held a rock-paper-scissors contest for UNIST students and gathered NN participants.
The contest consists of MM games in total. In each game, two or three participants make one of the three hand gestures—rock, paper, or scissors—all at once. Then the winner of each game is determined according to the following rules.

  • Rock wins scissors, scissors win paper, and paper wins rock.
  • If everyone makes the same hand gestures, the game draws.
  • If all three types of hand gestures appear, the game draws.
  • If the game doesn't draw, everyone who makes a winning hand gesture wins.

Each UNIST student had prepared one of the following strategies for this contest.

  • Always play the same hand gesture.
  • Play the three hand gestures once each, in any order. Repeat the same pattern for every three games this player participates in.

Unfortunately, Yunee couldn't watch the contest because of a lot of paperwork. But Yunee has a document that lists the participants and the winners of each game. Yunee wondered what strategies the students might have used. Find the number of possible strategy combinations of all students, modulo 109+710^9+7.

입력

The first line contains two integers NN and MM (3N300,1M300)(3 \leq N \leq 300, 1 \leq M \leq 300). NN represents the number of participants of the contest. MM represents the number of games.

The next MM lines contain the descriptions for the MM games in chronological order. Each game is described as follows.

  • The number of participants aa is given. (a=2 or a=3)(a=2\text{ or }a=3)
  • The participants' numbers p_1,,p_ap\_1, \cdots, p\_a are given. They are distinct integers ranging from 11 to NN.
  • A delimiter / is given.
  • The number of winners bb is given. If the game draws, b=0b = 0. (0b<a)(0\leq b < a)
  • The winners' numbers q_1,,q_bq\_1, \cdots, q\_b are given. They are distinct integers among p_1,,p_ap\_1, \cdots, p\_a.

출력

Output the number of possible strategy combinations of all students, modulo 109+710^9+7.