#D6171. Product
Product
Product
Problem
Aizu decided to play a game using a prime number , a set of natural numbers , and a natural number .
First, Aizu writes on the paper at hand. After that, perform the following series of operations any number of times.
- Select one element from . Let this be .
- Write a new product of the number written on the paper at hand and on the paper.
- Erase the number originally written on the paper.
If is equal to the number written on the paper at hand divided by , Aizu wins, otherwise he loses. Determine if Aizu can win when , , and are given.
Constraints
The input satisfies the following conditions.
- All inputs are integers.
- if
- The sum of in all test cases does not exceed .
Input
The input is given in the following format.
The input consists of multiple test cases. First, the line is given the prime number and the number of test cases . is common to all test cases. Each test case is given in the following line.
Each test case is given as follows.
In each test case, the number of elements of , each element of , and are given in order, separated by a space.
Output
For each test case, if Aizu can win, will be output on one line, otherwise will be output on one line.
Examples
Input
7 3 1 1 2 1 2 1 3 1 2 4 5
Output
0 1 0
Input
1000000007 8 3 2 9 7 5 3 2 9 5 1000001 3 39 1002 65537 12 2 1000000006 518012930 793649232 10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264 1 1 1 1 1 1000000006 1 1000000006 1
Output
0 1 1 1 0 1 0 1
inputFormat
input satisfies the following conditions.
- All inputs are integers.
- if
- The sum of in all test cases does not exceed .
Input
The input is given in the following format.
The input consists of multiple test cases. First, the line is given the prime number and the number of test cases . is common to all test cases. Each test case is given in the following line.
Each test case is given as follows.
In each test case, the number of elements of , each element of , and are given in order, separated by a space.
outputFormat
Output
For each test case, if Aizu can win, will be output on one line, otherwise will be output on one line.
Examples
Input
7 3 1 1 2 1 2 1 3 1 2 4 5
Output
0 1 0
Input
1000000007 8 3 2 9 7 5 3 2 9 5 1000001 3 39 1002 65537 12 2 1000000006 518012930 793649232 10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264 1 1 1 1 1 1000000006 1 1000000006 1
Output
0 1 1 1 0 1 0 1
样例
1000000007 8
3 2 9 7 5
3 2 9 5 1000001
3 39 1002 65537 12
2 1000000006 518012930 793649232
10 459268180 313723762 835892239 612038995 90424474 366392946 38051435 854115735 5132833 320534710 421820264
1 1 1
1 1 1000000006
1 1000000006 1
0
1
1
1
0
1
0
1
</p>