1 import java.io.*; 2 import java.util.*; 3 public class Main{ 4 public static void main(String[] args) { 5 Scanner input = new Scanner(System.in); 6 int a, b; int n; 7 while (input.hasNext()) { 8 a = input.nextInt(); 9 b = input.nextInt(); 10 n = input.nextInt(); 11 if (a == 0 && b == 0 && n == 0) 12 System.exit(0); 13 int f[] = new int[50]; 14 for (int i = 1; i < 50; i++) { 15 if (i == 1 || i == 2) { 16 f[i] = 1; 17 } 18 else { 19 f[i] = (a * f[i - 1] + b * f[i - 2]) % 7; 20 } 21 } 22 System.out.println(f[n % 49]); 23 } 24 } 25 }