First line of the input file contains an integer T(0 < T ≤ 10) that indicates how many cases of inputs are there.
The description of each case is given below:
The first line contains two integers Q and M. The next Q lines contains the operations in ith line following form:
M yi: x = x * yi.
N di: x = x / ydi.
It’s ensure that di is different. That means you can divide yi only once after yi came up.
0 < yi ≤ 10^9, M ≤ 10^9
For each operation, print an integer (one per line) x % M.
1 10 1000000000 M 2 D 1 M 2 M 10 D 3 D 4 M 6 M 7 M 12 D 7
2 1 2 20 10 1 6 42 504 84