Musical Instruments

Julio is a musician who teaches classical music at secondary school. Julio has N musical instruments to distribute among his M students, N ≥ M. To make an adequate distribution, Julio asked each student to list the N musical instruments in order of priority. Julio wants to make a distribution in which the biggest number of students have their favourite musical instrument, but there may be several possibilities. He wants to know how many possible arrangements –maximizing the assignment of the first priority– can be obtained. You must write a program which computes how many different distributions are possible, supposing the biggest number of students have their favourite musical instrument. Input The first line of the input contains the number of test cases. For each test case, there is a line with two numbers, N indicating the number of musical instruments, and M indicating the number of students, 32 ≥ N ≥ M. Subsequently, M lines are listed, one for each student; each line contains, separated by one space, N numbers between 1 and N which determine the priority of the corresponding student. The first number is the priority of the first musical instrument, the second number is the priority of the second musical instrument, and so on. Output For every test case you are to print a line containing a number which represents how many possible distributions can be obtained. Sample Input 4 10 6 1 2 3 4 5 6 7 8 9 10 4 5 6 7 8 9 10 1 2 3 6 7 8 9 10 1 2 3 4 5 7 8 9 10 1 2 3 4 5 6 9 10 1 2 3 4 5 6 7 8 9 10 3 4 5 6 7 8 1 2 12 4 3 4 5 6 7 8 9 10 1 2 11 12 7 8 9 10 1 2 6 11 12 3 4 5 4 5 6 7 8 9 10 12 1 2 3 11 12 5 6 7 8 9 10 1 2 3 4 11 64 231456 231456 612345 512346 21 12

2/2 Sample Output 1 2 4 1