#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(){
int a0,a1,p,q,k;
while(scanf("%d%d%d%d%d",&a0,&a1,&p,&q,&k) != EOF){
stack <int > sta;
sta.push(a0);
sta.push(a1);
for (int i = 2; i <= k; i ++){
int an1 = sta.top();
sta.pop();
int an2 = sta.top();
sta.pop();
sta.push(an1);//保存最近的两个
sta.push(p * an1 + q* an2);
}
printf("%d\n",sta.top()%10000);
}
return 0;
}
01-26
1131