CF1328C.Ternary XOR

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A number is ternary if it contains only digits 00 , 11 and 22 . For example, the following numbers are ternary: 10221022 , 1111 , 2121 , 20022002 .

You are given a long ternary number xx . The first (leftmost) digit of xx is guaranteed to be 22 , the other digits of xx can be 00 , 11 or 22 .

Let's define the ternary XOR operation \odot of two ternary numbers aa and bb (both of length nn ) as a number c=abc = a \odot b of length nn , where ci=(ai+bi)%3c_i = (a_i + b_i) \% 3 (where %\% is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by 33 . For example, 1022211021=2121010222 \odot 11021 = 21210 .

Your task is to find such ternary numbers aa and bb both of length nn and both without leading zeros that ab=xa \odot b = x and max(a,b)max(a, b) is the minimum possible.

You have to answer tt independent test cases.

输入格式

The first line of the input contains one integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases. Then tt test cases follow. The first line of the test case contains one integer nn ( 1n51041 \le n \le 5 \cdot 10^4 ) — the length of xx . The second line of the test case contains ternary number xx consisting of nn digits 0,10, 1 or 22 . It is guaranteed that the first digit of xx is 22 . It is guaranteed that the sum of nn over all test cases does not exceed 51045 \cdot 10^4 ( n5104\sum n \le 5 \cdot 10^4 ).

输出格式

For each test case, print the answer — two ternary integers aa and bb both of length nn and both without leading zeros such that ab=xa \odot b = x and max(a,b)max(a, b) is the minimum possible. If there are several answers, you can print any.

输入输出样例

  • 输入#1

    4
    5
    22222
    5
    21211
    1
    2
    9
    220222021

    输出#1

    11111
    11111
    11000
    10211
    1
    1
    110111011
    110111010
首页