CF1927A.Make it White

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Make it White

You have a horizontal strip of nn cells. Each cell is either white or black.

You can choose a continuous segment of cells once and paint them all white. After this action, all the black cells in this segment will become white, and the white ones will remain white.

What is the minimum length of the segment that needs to be painted white in order for all nn cells to become white?

Input

The first line of the input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. The descriptions of the test cases follow.

The first line of each test case contains a single integer nn (1n101 \le n \le 10) — the length of the strip.

The second line of each test case contains a string ss, consisting of nn characters, each of which is either 'W' or 'B'. The symbol 'W' denotes a white cell, and 'B' — a black one. It is guaranteed that at least one cell of the given strip is black.

Output

For each test case, output a single number — the minimum length of a continuous segment of cells that needs to be painted white in order for the entire strip to become white.

Note

In the first test case of the example for the strip "WBBWBW", the minimum length of the segment to be repainted white is 44. It is necessary to repaint to white the segment from the 22-nd to the 55-th cell (the cells are numbered from 11 from left to right).

Samples

8
6
WBBWBW
1
B
2
WB
3
BBW
4
BWWB
6
BWBWWB
6
WWBBWB
9
WBWBWWWBW
4
1
1
2
4
6
4
7

在线编程 IDE

建议全屏模式获得最佳体验