// hdoj_1005 Number Sequence
// 31MS 220K 370 B GCC
#include <stdio.h>
int fun(int a, int b, __int64 n);
int main(void)
{
int a, b;
__int64 n;
while(scanf("%d%d%I64d", &a, &b, &n) && a != 0 && b != 0 && n != 0)
{
printf("%d\n", fun(a, b, n%49));
}
return 0;
}
int fun(int a, int b, __int64 n)
{
if(n == 1 || n == 2)
return 1;
else
return (a*fun(a, b, n-1) + b*fun(a, b, n-2)) % 7;
}