CF BUDDY
← Problems·

1954C · Long Multiplication

1200 · greedy, math, number theory

Problem: You are given two integers xx and yy of the same length, consisting of digits from 11 to 99.

You can perform the following operation any number of times (possibly zero): swap the ii-th digit in xx and the ii-th digit in yy.

For example, if x=73x=73 and y=31y=31, you can swap the 22-nd digits and get x=71x=71 and y=33y=33.

Your task is to maximize the product of xx and yy using the aforementioned operation any number of times. If there are multiple answers, print any of them.

Input Format: The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases.

The first line of each test case contains a single integer xx (1x<101001 \le x < 10^{100}).

The second line of each test case contains a single integer yy (1y<101001 \le y < 10^{100}).

Additional constraint on input: the integers xx and yy consist only of digits from 11 to 99.

Output Format: For each test case, print two lines — the first line should contain the number xx after performing the operations; similarly, the second line should contain the number yy after performing the operations. If there are multiple answers, print any of them.

Sample Cases

Case 1

Input

3
73
31
2
5
3516
3982

Output

71
33
5
2
3912
3586

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback