#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100;
int a, b, n;
int f[N];
int main()
{
f[1] = 1, f[2] = 1;
while (cin >> a >> b >> n && (a + b + n))
{
int i;
for (i = 3; i < 100; i ++ )
{
f[i] = (a * f[i - 1] + b * f[i - 2]) % 7;
if (f[i] == 1 && f[i - 1] == 1)
break; // //当找到两个连续1时走完一个周期周期为i-2
}
f[0] = f[i - 2];
n = n % (i - 2);
cout << f[n] << endl;
}
return 0;
}