Under construction

Still being built. Things may change

Flip

Time limit10sMemory limit512 MB

Summary
Given sets of people numbered 1 to 2n, find for each set the probability that all its members land on the same team under the coin-flip assignment, modulo 998244353.
Level

Hard8 of 10

Topics
Combinatorics, Math, Prefix sum
Solved
No attempts yet

Problem

Assume people numbered from 11 to 2n2n are assigned to two teams of size nn using the following procedure. Find, for each given set A1,A2,…,AmA^1, A^2, \dots, A^m, the probability that all people in that set end up on the same team. Display it modulo 998 244 353.

  • In order from 11 to 2n2n, each person flips a fair coin.
  • If the coin lands heads up, the person joins the first team, unless that team already has nn people. In that case, the person joins the second team.
  • If the coin lands tails up, the person joins the second team, unless that team already has nn people. In that case, the person joins the first team.

Input

The first line contains two integers nn and mm (2≤n≤1052 \le n \le 10^5; 1≤m≤1051 \le m \le 10^5).

The ii-th of the next mm lines describes set AiA^i. It contains an integer kik_i (2≤ki≤n2 \le k_i \le n), followed by kik_i integers a1i,a2i,…,akiia^i_1, a^i_2, \dots, a^i_{k_i} (1≤a1i<a2i<⋯<akii≤2n1 \le a^i_1 < a^i_2 < \dots < a^i_{k_i} \le 2n).

The sum of all kik_i does not exceed 2⋅1052 \cdot 10^5.

Output

For each ii from 11 to mm, display the probability that all people from the set AiA^i end up on the same team.

It can be shown that any such probability can be written as an irreducible fraction pq\frac{p}{q} with q≢0(mod998 244 353)q \not\equiv 0 \pmod{998\,244\,353}. Then there is a unique integer rr with r⋅q≡p(mod998 244 353)r \cdot q \equiv p \pmod{998\,244\,353} and 0≤r<998 244 3530 \le r < 998\,244\,353. Display this rr.

Hint

In the first test case, people 11 and 22 (and people 33 and 44) end up on the same team with probability 12\frac{1}{2}. For any other pair, the probability is 14\frac{1}{4}.

Examples2

  1. Example 1

    Input
    2 6
    2 1 2
    2 1 3
    2 1 4
    2 2 3
    2 2 4
    2 3 4
    
    Expected output
    499122177
    748683265
    748683265
    748683265
    748683265
    499122177
    
  2. Example 2

    Input
    3 5
    3 2 3 5
    2 2 4
    2 5 6
    3 1 4 6
    2 2 5
    
    Expected output
    935854081
    623902721
    374341633
    935854081
    686292993