Zombinatorial

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
You are given a function f which is defined as :
Your task is to find the value of
where M is given in input.
Input Format
First line contains T, the number of test cases.
First line of each test case contain 3 space separated integers N, M and Q.
Next Q line follows, each line contain r.
Output Format
For each test case, output Q lines, each line containing the required answer.
Constraints
2 ≤ N ≤ 10^{6}
1 ≤ M ≤ 10^{9}
2 ≤ Sum of N over all test cases ≤ 10^{6}
1 ≤ Sum of Q over all test cases ≤ 2*10^{5}
1 ≤ T ≤ 10^{5}
1 < r < N
Sample Input 2 5 114 1 2 50 3874 3 31 17 21 Sample Output 72 3718 624 1144
Explanation for first test case
f[1] = 1
f[2] = 2
f[3] = 1*2^{2} * 3 = 12
f[4] =1*2^{3}*3^{2}*4 = 8*9*4 = 288
f[5] = 1*2^{4}*3^{3}*4^{2}*5 =34560
value of f[5] / (f[2]*f[3]) = 1440 and 1440 %114 is 72
Author:  devuy11 
Tester:  anudeep2011 
Editorial  http://discuss.codechef.com/problems/FOMBRO 
Tags  cook55, devuy11, dynamicprogramming, mathematics, simple 
Date Added:  11112014 
Time Limit:  4 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 