#P9888. [ICPC 2018 Qingdao R] Magic Multiplication

[ICPC 2018 Qingdao R] Magic Multiplication

题目描述

BaoBao is now learning a new binary operation between two positive integers, represented by \otimes, in his magic book. The book tells him that the result of such operation is calculated by concatenating all multiple results of each digit in the two integers.

Formally speaking, let the first integer be A=a1a2anA = a_1a_2 \dots a_n, where aia_i indicates the ii-th digit in AA, and the second integer be B=b1b2bmB = b_1b_2 \dots b_m, where bib_i indicates the ii-th digit in BB. We have

$$A \otimes B = \sum\limits_{i=1}^n\sum\limits_{j=1}^m a_ib_j = a_1b_1 + a_1b_2 + \dots + a_1b_m + a_2b_1 + \dots + a_nb_m $$

Note that the result of aibja_ib_j is considered to be a string\textbf{string} (without leading zeros if aibj>0a_ib_j > 0, or contains exactly one 0 if aibj=0a_ib_j = 0), NOT a normal integer. Also, the sum here means string concatenation\textbf{string concatenation}, NOT the normal addition operation.

For example, 2345=810121523 \otimes 45 = 8101215. Because 8=2×48=2 \times 4, 10=2×510=2 \times 5, 12=3×412=3 \times 4 and 15=3×515=3 \times 5.

BaoBao is very smart and soon knows how to do the inverse operation of \otimes. Now he gives you the result of a \otimes operation and the numbers of digits in the two original integers. Please help him to restore the two original integers AA and BB.

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two positive integers nn and mm (1n,m2×1051 \le n, m \le 2 \times 10^5), where nn indicates the length of AA and mm indicates the length of BB. Here length of an integer means the length of the string when writing the number in decimal notation without leading zeros.

The second line contains only one positive integer CC without leading zeros, indicating the result of ABA \otimes B. The length of CC is no more than 2×1052 \times 10^5.

It's guaranteed that the sum of lengths of CC over all test cases will not exceed 2×1062 \times 10^6.

输出格式

For each test case output one line.

If there exist such AA and BB that AB=CA \otimes B = C, output one line containing two integers AA and BB separated by one space. Note that AA and BB should be positive integers without leading zeros, the length of AA should be exactly nn, and the length of BB should be exactly mm.

If there are multiple valid answers, output the answer with the smallest AA; If there are still more than one answer, output one of them with the smallest BB.

If such AA and BB do not exist, print Impossible (without quotes) on a single line.

4
2 2
8101215
3 4
100000001000
2 2
80101215
3 4
1000000010000
23 45
101 1000
Impossible
Impossible