시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 23 7 7 30.435%

문제

팩스는 Run-Length Encoding(RLE)라고 불리는 인코딩을 사용한다. RLE란 아주 단순한 데이터 압축으로 데이터를 데이터와 반복된 횟수로 저장하는 방식을 말한다. 이 방식은 상대적으로 단순한 그래픽 이미지(아이콘, 글, 선 긋기)와 같이 반복이 많은 데이터를 압축할 때 좋다. 그러나 사진과 같이 반복이 별로 없다면 별로 좋지 않고, 거의 파일 크기를 두배로 늘린다.

아주 간단한 RLE 알고리즘을 이용하여 데이터 뭉치를 해독하는 프로그램을 작성해야 한다.

run은 2바이트를 사용하여 인코딩된다. 첫 번째 바이트는 반복횟수(count)를 뜻하고, 두 번째 바이트는 반복될 문자(값,value)를 뜻한다.

count 바이트는 첫 번째 비트가 1이며, 남은 7개의 비트로 [반복될 횟수-3]을 저장한다. 그러므로 최대 130번의 반복까지 저장할 수 있다. (즉 3회이상 반복되어야 이런 형식으로 인코딩된다는 뜻이다.) 값을 저장하는 value 바이트는 첫 번째 비트가 0이며 남은 7개의 비트로 [값-1]형태로 저장하여 1부터 128까지의 값을 저장할 수 있다.

입력

첫째 줄은 데이터 세트 수 P(1 ≤ P ≤ 1000)가 입력으로 들어온다. 각각의 데이터 세트는 여러 줄로 구성되어 있는데, 첫째 줄은 문제 번호와 디코딩해야 할 바이트 수 B(1 ≤ B ≤ 5000)가 공백으로 구분되어 들어온다. 남은 줄은 디코드해야할 데이터로 구성되어 있다. 데이터는 한 줄에 각 80개의 16진법 숫자이며 (마지막 줄은 80개보다 적을 수 있다), 16진법 숫자 2개가 하나의 바이트를 나타낸다.

(16진법 수는 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F로 구성되어 있다)

출력

각각의 데이터 세트에 대해 여러 줄의 출력을 해야한다. 첫째 줄은 코딩한 바이트 수를 출력한다. 남은 줄은 디코딩한 데이터를 출력하는데, 한 줄에 80개의 16진수로 출력한다. (마지막 줄은 80개보다 적을 수 있다)

예제 입력 1

4
2
0007
4
00F481A5
32
850080FF016666825A0A717273747580080110111384550301020399807700CC
2
A568

예제 출력 1

1
07
5
F4A5A5A5A5
44
0000000000000000FFFFFF66665A5A5A5A5A71727374758008011011135555555555555501020399
777777CC
40
68686868686868686868686868686868686868686868686868686868686868686868686868686868
W3sicHJvYmxlbV9pZCI6IjI2ODciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzMjlcdWMyYTQgXHViYzFiXHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cclxuXHRcdWQzMjlcdWMyYTRcdWIyOTQgUnVuLUxlbmd0aCBFbmNvZGluZyhSTEUpXHViNzdjXHVhY2UwIFx1YmQ4OFx1YjlhY1x1YjI5NCBcdWM3NzhcdWNmNTRcdWI1MjlcdWM3NDQgXHVjMGFjXHVjNmE5XHVkNTVjXHViMmU0LiBSTEVcdWI3ODAgXHVjNTQ0XHVjOGZjIFx1YjJlOFx1YzIxY1x1ZDU1YyBcdWIzNzBcdWM3NzRcdWQxMzAgXHVjNTU1XHVjZDk1XHVjNzNjXHViODVjIFx1YjM3MFx1Yzc3NFx1ZDEzMFx1Yjk3YyBcdWIzNzBcdWM3NzRcdWQxMzBcdWM2NDAgXHViYzE4XHViY2Y1XHViNDFjIFx1ZDY5Zlx1YzIxOFx1Yjg1YyBcdWM4MDBcdWM3YTVcdWQ1NThcdWIyOTQgXHViYzI5XHVjMmRkXHVjNzQ0IFx1YjlkMFx1ZDU1Y1x1YjJlNC4gXHVjNzc0IFx1YmMyOVx1YzJkZFx1Yzc0MCBcdWMwYzFcdWIzMDBcdWM4MDFcdWM3M2NcdWI4NWMgXHViMmU4XHVjMjFjXHVkNTVjIFx1YWRmOFx1Yjc5OFx1ZDUzZCBcdWM3NzRcdWJiZjhcdWM5YzAoXHVjNTQ0XHVjNzc0XHVjZjU4LCBcdWFlMDAsIFx1YzEyMCBcdWFlMGJcdWFlMzApXHVjNjQwIFx1YWMxOVx1Yzc3NCBcdWJj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