#include<bits/stdc++.h> using namespace std; int n,k,i; char s[1005],ch; int main(){ cin>>n>>ch>>k; cin>>s; for(i=0;i<strlen(s);++i){//模拟所有操作 if(s[i]=='a')n=(n*k)%1000; if(s[i]=='b')n=(n+k)%1000; if(s[i]=='c')n=abs(n-k); if(s[i]=='d')n=n/k; } cout<<n; return 0; }