Numerals of the Przesmyks

No attempts yetTime limit1sMemory limit128 MB

Problem

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 mm - symbols may appear in a row. The bound mm changed from year to year and always lay between 1 and 113.

Once the bound mm 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=1m = 1), the numerals begin like this:

NNumeralNNumeralNNumeral
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.

Input

The first line contains three integers m1m_1, m2m_2 and nn separated by single spaces, where 1m1,m21131 \le m_1, m_2 \le 113 and 1n101 \le n \le 10. Here m1m_1 is the bound on the maximum number of consecutive - symbols in the input numerals, and m2m_2 is the bound for the numerals that must be written out. nn is the number of numerals to convert.

Each of the next nn lines contains one numeral, a string of - and +. No numeral is longer than 1000 characters.

Output

Print nn lines. On each line print the corresponding input number rewritten under the bound m2m_2.