Chef and Strange Operations

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has an array A consisting of N integers (1based indexing). He asks you to perform the following operation M times:
for i = 2 to N:
A_{i} = A_{i} + A_{i1}
Your task is to find the x^{th} element of the array (i.e., A_{x}) after performing the above operation M times. As the answer could be large, please output it modulo 10^{9} + 7.
Input
 The first line of input contains an integer T denoting the number of test cases.
 The first line of each test case contains three spaceseparated integers — N, x, and M — denoting the size of the array, index of the element you need to find, and the amount of times you need to repeat operation before finding the element, respectively. The second line contains N spaceseparated integers A_{1}, A_{2}, …, A_{N}.
Output
For each test case, output a single line containing one integer: A_{x} modulo 10^{9} + 7.
Constraints
 1 ≤ T ≤ 10
 1 ≤ x ≤ N ≤ 10^{5}
 1 ≤ M ≤ 10^{18 }
 1 ≤ A_{i } ≤ 10^{18}
Subtasks
Subtask 1 (8 points): 1 ≤ x ≤ min{2, N}
 1 ≤ N * M ≤ 10^{6}
Example
Input: 2 3 2 3 1 2 3 3 3 3 1 2 3 Output: 5 15
Explanation
Values in the array A:
 Before the operations: [1, 2, 3]
 After the first operation: [1, 3, 6]
 After the second operation: [1, 4, 10]
 After the third operation: [1, 5, 15]
Since input file can be fairly large (about 8 MB), it's recommended to use fast I/O (for example, in C++, use scanf/printf instead of cin/cout).
Author:  antoniuk1 
Tester:  iscsi 
Editorial  http://discuss.codechef.com/problems/STROPR 
Tags  antoniuk1, combinatorics, easy, feb16, maths 
Date Added:  23012015 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, 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, SCM chicken, 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. 