没办法,用python就是会超时,T_T

T = int(input().split()[0])

for _ in range(T):
    A, B, n = list(map(int, input().split()))
    a, b, c = A, (A**2 - 2*B) % (1e9+7), 0
    if n == 1:
        print(a)
    if n == 2:
        print(b)
    while n > 2:
        c = (A*b - B*a)%(1e9+7)
        # c = A*b % (1e9 + 7) - B*a % (1e9+7)
        a = b
        b = c
        n -= 1
    print(int(c))