Roh has recently started working on a new project and he really enjoys working on it. The thing that annoys him, however, is that the requirements seem to keep changing continuously. Everyday, Roh's supervisor Zach comes to him with a new list of requirements that Roh must fulfill. The ever-changing requirements have frustrated Roh and he wishes for once that Zach could make up his mind.
Roh's task is simple. He must construct an array a[1 ... n] of size n, whose elements are positive integers greater than 1. Everyday Zach comes to Roh with a new set of requirements. The requirement on the i-th day is defined by a subset of indices, Si. For any two indices x, y such that x ∈ Si and y ∉ Si, it is required that gcd(a[x], a[y]) = 1.
On the i-th day, Roh must construct an array of positive integers a[1 ... n] of size n, such that:
- a[i] ≥ 2 or all 1 ≤ i ≤ n.
- The array satisfies all requirements up to day i, ie. it complies with each of the sets S1 , S2 , S3 , ..., Si.
Of course, there might be many such arrays and Roh must find the array with the minimum sum of elements. Zach doesn’t have the time to go through all of Roh's work. So, he asks Roh to report only two numbers, the minimum sum of elements that Roh can achieve, and the number of valid arrays with the minimum sum.
Help Roh complete his task.
Input
The first line contains T, the number of test cases.
The first line of each case contains two integers n, and q denoting the number of elements and the number of requirements.
It is followed by q lines. The ith line describes the set Si. It starts with an integer k denoting the number of elements of Si. Then k distinct integers follow Si,1, Si,2, Si,3, ..., Si,k the elements of Si.
Constraints
- 1 ≤ T ≤ 100
- 2 ≤ n ≤ 105
- 1 ≤ q ≤ 105
- 1 ≤ k ≤ n
- 1 ≤ Si,j ≤ n for all 1 ≤ j ≤ k
- All elements of a set Si are distinct, ie. Si,1 , Si,2, …, Si,k are distinct.
- Sum of n over all cases does not exceed 5 x 105 .
- Sum of q over all cases does not exceed 5 x 105
- The total number of elements over all sets over all test cases does not exceed 106.
Output
For each test case, print q lines. The ith line for each case should contain two space-separated integers. The first integer is the minimum sum of a valid array that fulfills all requirements upto day i. The second integer is the number of valid arrays with the minimum sum. Since the number of valid arrays can be large, print the number of valid arrays modulo 998244353.
Sample
Sample Input | Sample Output |
---|---|
1 4 2 2 1 2 3 1 2 3 | 10 2 12 2 |
Notes
For the first day, 2, 2, 3, 3 and 3, 3, 2, 2 are the interesting sets with the minimum sum. For the second day, 2, 2, 3, 5 and 2, 2, 5, 3 are the interesting sets with the minimum sum.