시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 24 13 13 54.167%

문제

만칼라는 보드 게임의 한 종류로, 여러 변형 판이 존재한다.

그 중 가장 간단한 종류인 1인용 만칼라 게임 Tchoukaillon에 대해 살펴볼 것이다.

Tchoukaillon는 여러 개의 빈칸과 하나의 Roumba로 이루어진 보드 위에서 진행된다.

가장 왼쪽의 빈칸은 Roumba이며, 처음엔 항상 비어있는 상태여야 한다.

게임은 다음과 같이 진행된다. 우선, 각 칸을 B[N]이라 할 때, B[N]에 N개의 구슬이 들어 있는 칸을 찾는다. 그런 칸이 여러 개라면 아무 것이나 선택해도 상관없다. 만일 B[N]=N인 칸이 없다면 그 판은 패배이다.

위의 예제에서는 맨 첫 줄을 보면 된다. 3번 칸을 선택한 상황이다.

이제 고른 칸의 구슬을 Roumba와 B[1], B[2], ... , B[N-1]에 하나씩 고르게 나누어준다.

위의 시행을 계속 반복하여 모든 구슬이 Roumba로 들어간다면 게임을 성공적으로 마치게 되는 것이고, 이처럼 성공이 가능한 모든 게임판을 승리하는 게임판이라고 한다. 모든 정수 N에 대해, 구슬이 총 N개일 때의 승리하는 게임판은 항상 유일하다. 따라서 위에서의 Roumba를 뺀 보드판의 초기 상태 { 0, 1, 3 } 은 구슬이 4개일 때의 유일한 승리하는 게임판이다.

총 구슬의 개수 N이 주어지면 승리하는 게임판을 출력하라.

입력

첫 줄에 테스트 케이스의 수 P가 주어진다. (1 ≤ P ≤ 1000)

각 테스트 케이스는 테스트 케이스의 번호 T와 보드판에 들어갈 구슬의 총 개수 N으로 이루어져 있다.

출력

각 테스트 케이스마다 첫 줄에 테스트 케이스의 번호 T와 구슬이 하나 이상 담겨 있는 보드판의 마지막 위치 B를 출력한다.

그 후 승리하는 게임판의 상태를 B개의 정수로 출력하는데, 수는 10개 단위로 끊어서 출력해야 한다.

모든 테스트 케이스에서 B는 80을 넘지 않는다.

예제 입력 1

3
1 4
2 57
3 500

예제 출력 1

1 3
0 1 3
2 12
1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