Consider the generalized Fibonacci number G, which is dependent on a, b and c as follows :-
G(1) = 1
G(2) = 1
G(n) = aG(n-1) + bG(n-2) + c.
Your task is to calculate G(n)%m for given values of n and m.
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains five space separated values a, b, c, n, m respectively.
For each test case in a new line print the required output denoting G(n).
1<=a, b, c, n, m<=10^9+7
3 3 3 3 5
2 2 2 4 100