A fantastic sequence ai is defined in the following
way:
are given integers, and
the subsequent elements are defined by the linear
recurrence relation
You have to find an mod m , where n and m are given.
The first line of the input contains the number of the test
cases, which is at most 20. The descriptions of the test cases follow.
The first line of a test case description contains three integers k
(0 ≤ k ≤ 25), m (
), and n (
) separated by spaces. The second line contains the
integers
separated by spaces
(
). The third line contains the
integers
separated by spaces
(
).
The test cases are separated by blank lines.
For each test case in the input, output one nonnegative integer: an mod m . Print a blank line between test cases.
Input | Output |
1 2 10 10 1 1 0 1 1 | 9 |