시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 64 29 24 45.283%

문제

서로 다른 크기의 n개의 팬케익이 쌓여 있다. 순서 없이 마구 쌓여져있는 팬케익을 크기 순대로 쌓으려고 한다. 가장 위에는 제일 작은 크기의 팬케익이 있어야 되고, 가장 아래에는 제일 큰 크기의 팬케익이 있어야 한다.

팬케익을 뒤집는 방법은 위에서 k개의 순서를 뒤집는 것이다. 따라서 k번째 팬케익이 가장 위로 올라오게 되고, 제일 위에 있던 팬케익은 k번째가 된다.

다음 예를 보자.

팬케익이 쌓여있는 상태가 주어졌을 때, 이를 순서대로 만드는 방법을 찾아 출력하는 프로그램을 작성하시오. 팬케익은 최대 2n-3번 뒤집을 수 있다.

입력

첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 숫자 여러개가 공백으로 구분되어있다. 첫 번째 숫자는 팬케익의 개수 N이고, 그 다음 N개의 숫자는 팬케익의 크기이다. 가장 위에 있는 팬케익이 첫 숫자이고, 마지막 숫자는 제일 아래에 있는 팬케익이다.  N은 30보다 작거나 같다. 팬케익의 크기는 서로 다르며, 1보다 크거나 같고, N보다 작거나 같다.

출력

각 테스트 케이스에 대해 한 줄에 하나씩 뒤집는 방법을 출력한다. 제일 먼저 뒤집는 횟수 K를 출력한다. 그 다음 뒤집는 방법을 순서대로 출력하면 된다. 뒤집는 방법이 여러개일 때는, 아무거나 출력하면 된다.

예제 입력 1

2
3 1 3 2
5 4 3 2 5 1

예제 출력 1

3 2 3 2
3 3 4 5
W3sicHJvYmxlbV9pZCI6IjI3NTkiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQzMmNcdWNmMDBcdWM3NzUgXHViNGE0XHVjOWQxXHVhZTMwIiwiZGVzY3JpcHRpb24iOiI8cD5cclxuXHRcdWMxMWNcdWI4NWMgXHViMmU0XHViOTc4IFx1ZDA2Y1x1YWUzMFx1Yzc1OCBuXHVhYzFjXHVjNzU4IFx1ZDMyY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