Dr. Wright's class is studying a modified L-system. Here are the details you need.
Consider words of length $n$ over the two-letter alphabet ${a, b}$. Each word is cyclic: it can be written in any of its $n$ cyclic-shift forms, and the first and last letters are treated as neighbours.
A rewriting rule replaces the letter at a position $i$ based on the letters at positions $i-2$, $i$, and $i+1$ (indices are taken cyclically). In one step, all letters of the word are rewritten simultaneously.
Given a starting word and a set of rewriting rules, determine how the word looks after $s$ rewriting steps.
The input contains several blocks, each describing one system.
a and b.Process blocks until the end of input.
For each block, print one line containing the word obtained after $s$ rewriting steps. Because the word is cyclic it can be written in any of its $n$ shifted forms; print the lexicographically smallest such form, assuming a < b.