/* Kristoffer Hansen. arnsfelt@daimi.au.dk */ #include #include #include char rules[8]; int ruleindex(char c1, char c2, char c3) { return (c1-'a')*4+(c2-'a')*2+(c3-'a'); } string rotate(string x) { string y,rx; string::size_type i; rx=x; for (i=0; i0) fx = f(fx); return fx; } int main() { int n,s; string x,r; while (cin >> n) { cin >> x; while (scanf("%d",&s)==0) { cin >> r; rules[ruleindex(r[0],r[1],r[2])]=r[3]; } cout << apply(rotate(x),s) << "\n"; } return 0; }