A tribe called the Przesmyks wrote natural numbers using only two symbols, - and +. Every legal numeral is a non-empty string of these two symbols that obeys a single rule: no more than m - symbols may appear in a row. The bound m changed from year to year and always lay between 1 and 113.
Once the bound m is fixed, all legal strings are ordered first by length (shorter strings first) and then, among strings of equal length, alphabetically, where - comes before +. Listed in this order, the strings represent the successive numbers 0, 1, 2, ….
For example, when at most one - in a row is allowed (m=1), the numerals begin like this:
| N | Numeral | N | Numeral | N | Numeral |
|---|---|---|---|---|---|
| 0 | - | 4 | ++ | 8 | ++- |
| 1 | + | 5 | -+- | 9 | +++ |
| 2 | -+ | 6 | -++ | 10 | -+-+ |
| 3 | +- | 7 | +-+ | 11 | -++- |
When the bound changes, the way a number is written changes too. For instance, if two or more - in a row are allowed, the number 2 is written as --.
Write a program that reads two bounds and a list of numbers written under the first bound, and rewrites each of them under the second bound.
The first line contains three integers m1, m2 and n separated by single spaces, where 1≤m1,m2≤113 and 1≤n≤10. Here m1 is the bound on the maximum number of consecutive - symbols in the input numerals, and m2 is the bound for the numerals that must be written out. n is the number of numerals to convert.
Each of the next n lines contains one numeral, a string of - and +. No numeral is longer than 1000 characters.
Print n lines. On each line print the corresponding input number rewritten under the bound m2.