403157: GYM101047 M Removing coins in Kem Kadrãn

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

M. Removing coins in Kem Kadrãntime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Andréh and his friend Andréas are board-game aficionados. They know many of their friends would love to go on a trip to Phuket, Thailand, and so they want to challenge them at Kem Kradãn, a traditional Thai board game.

Kem Kradãn (เกมกระดาน) has been played since the 2nd century AD. The game is played with N pieces where each piece has two faces, one of which is golden and the other is white. The game starts with all pieces arranged in a line on the board and they are numbered from 1 to N from left to right. When a piece numbered i has its golden face up, it can be removed from the board. When this is done, the pieces numbered i - 1 and i + 1 are flipped, if they're still there. The goal is to remove all game pieces.

Before challenging their friends, Andréh and Andréas want to make sure their initial configurations have a solution. To help them, given an initial configuration, you must determine if it is possible to remove all game pieces and, if so, you must show how to do it.

Input

The first line has a single integer T, the number of test cases.

Each test case is formed by a line containing an integer N, the number of pieces, followed by line containing a string of length N containing only the letters B (white face up) and D (golden face up), representing the initial state of the game.

Limits

  • 1 ≤ T ≤ 100
  • 1 ≤ N ≤ 105
  • The sum of N over all test cases will not exceed 5·105
Output

For each test case, print a line containing Y if it is possible to remove every piece from the board, or N otherwise. In case it is possible to remove all the pieces, you should also print on the next line a sequence of N integers each representing a piece number, indicating the order in which the pieces must be removed. If there is more than one possible sequence, you can print any of them.

ExampleInput
4
3
BDB
5
DBDDB
5
DDBDD
6
DBBBBB
Output
Y
2 3 1
Y
4 5 1 2 3
N
Y
1 2 3 4 5 6

Source/Category

加入题单

算法标签: