#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
const int N=1e5+10,mod=1e6;
const int MAX = 1e8 + 10 ;
/*矩阵快速幂;
fir_p 记录初始输入的p , fir_q记录初始输入的q
p , q , one , zero 不断更新成计算结果;
重复k-2次运算
|fir_p fir_q | |p q | = |tmp_p tmp_q |
|fir_one fir_zero| |one zero| |tmp_one tmp_zero|
*/
int a0 , a1 , k ;
int fir_p , fir_q , fir_one = 1 , fir_zero = 0;
int tmp_p , tmp_q , tmp_one , tmp_zero ;
int p , q , one = 1 , zero = 0 ;
void ju_zhen(int fir_p , int fir_q,int k){
p = fir_p ;
q = fir_q ;
one = fir_one ;
zero = fir_zero ;
for(int i = 1 ; i <= k-2 ; i++){
tmp_p = (fir_p*p + fir_q*one)%10000 ;
tmp_q = (fir_p*q + fir_q*zero)%10000 ;
tmp_one = (fir_one*p + fir_zero*one)%10000 ;
tmp_zero = (fir_one*q + fir_zero*zero)%10000 ;
p = tmp_p ;
q = tmp_q ;
one = tmp_one ;
zero = tmp_zero ;
}
int fk = (p*a1 + q*a0)%10000 ;
cout << fk <<endl;
}
int main(){
while(cin >> a0 >> a1 >> fir_p >> fir_q >> k){
ju_zhen(fir_p , fir_q,k) ;
}
}