All the description is the formula below.

One line per case, A, B, a, b, n, one by one. All of them are possitive integers less than 1000000000.

One line per case, output f(n) mod 5767169.

1 1 1 2 6 1 2 3 4 24

13 345