310841: CF1898A. Milica and String

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Milica and Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Milica has a string $s$ of length $n$, consisting only of characters A and B. She wants to modify $s$ so it contains exactly $k$ instances of B. In one operation, she can do the following:

  • Select an integer $i$ ($1 \leq i \leq n$) and a character $c$ ($c$ is equal to either A or B).
  • Then, replace each of the first $i$ characters of string $s$ (that is, characters $s_1, s_2, \ldots, s_i$) with $c$.

Milica does not want to perform too many operations in order not to waste too much time on them.

She asks you to find the minimum number of operations required to modify $s$ so it contains exactly $k$ instances of B. She also wants you to find these operations (that is, integer $i$ and character $c$ selected in each operation).

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 500$). The description of test cases follows.

The first line of each test case contains two integers $n$ and $k$ ($3 \leq n \leq 100$, $0 \leq k \leq n$) — the length of the string $s$ and the number of characters B Milica wants to appear in $s$ in the end.

The second line of each test case contains the string $s$ of length $n$, consisting only of characters A and B.

Output

For each test case, in the first line output a single integer $m$ — the minimum number of operations Milica should perform.

In the $j$-th of the next $m$ lines output an integer $i$ ($1 \le i \le n$) and a character $c$ ($c$ is 'A' or 'B') — the parameters of the $j$-th operation as described in the statement.

If there are multiple solutions with the minimum possible number of operations, output any of them.

ExampleInput
5
5 2
AAABB
5 3
AABAB
5 0
BBBBB
3 0
BAA
10 3
BBBABBBBAB
Output
0
1
1 B
1
5 A
1
2 A
1
6 A
Note

In the first test case, there are already $2$ characters B in $s$, so Milica does not have to perform any operations.

In the second test case, the only way to achieve $3$ characters B in $s$ in one operation is to replace the first character of $s$ by B on the first operation: AABAB $\rightarrow$ BABAB.

In the third test case, the only way to achieve $0$ characters B in $s$ in one operation is to replace the first $5$ characters of $s$ by A on the first operation: BBBBB $\rightarrow$ AAAAA.

In the fourth test case, one of the ways to achieve $0$ characters B in $s$ in one operation is to replace the first $2$ characters of $s$ by A on the first operation: BAA $\rightarrow$ AAA. Note that "1 A" and "3 A" are also correct one-operation solutions.

Output

题目大意:
Milica有一个长度为n的字符串s,只包含字符'A'和'B'。她想要通过一系列操作将字符串s修改为恰好包含k个'B'字符。在一次操作中,她可以选择一个整数i(1≤i≤n)和一个字符c('A'或'B'),然后将字符串s的前i个字符(即s1, s2, …, si)全部替换为c。Milica希望以最少的操作次数完成修改,并要求你找出这些操作(即每次操作选择的整数i和字符c)。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1≤t≤500),表示测试用例的数量。
- 每个测试用例包含两行:
- 第一行包含两个整数n和k(3≤n≤100,0≤k≤n),分别表示字符串s的长度和最终s中'B'字符的数量。
- 第二行包含一个长度为n的字符串s,只包含字符'A'和'B'。

输出:
- 对于每个测试用例,首先输出一个整数m,表示Milica需要执行的最少操作次数。
- 接下来m行,每行输出一个操作的两个参数:整数i(1≤i≤n)和字符c('A'或'B'),表示每次操作选择的参数。
- 如果存在多个最小操作次数的解决方案,输出其中任意一个即可。

示例输入输出见题目描述中的"Example"部分。题目大意: Milica有一个长度为n的字符串s,只包含字符'A'和'B'。她想要通过一系列操作将字符串s修改为恰好包含k个'B'字符。在一次操作中,她可以选择一个整数i(1≤i≤n)和一个字符c('A'或'B'),然后将字符串s的前i个字符(即s1, s2, …, si)全部替换为c。Milica希望以最少的操作次数完成修改,并要求你找出这些操作(即每次操作选择的整数i和字符c)。 输入输出数据格式: 输入: - 第一行包含一个整数t(1≤t≤500),表示测试用例的数量。 - 每个测试用例包含两行: - 第一行包含两个整数n和k(3≤n≤100,0≤k≤n),分别表示字符串s的长度和最终s中'B'字符的数量。 - 第二行包含一个长度为n的字符串s,只包含字符'A'和'B'。 输出: - 对于每个测试用例,首先输出一个整数m,表示Milica需要执行的最少操作次数。 - 接下来m行,每行输出一个操作的两个参数:整数i(1≤i≤n)和字符c('A'或'B'),表示每次操作选择的参数。 - 如果存在多个最小操作次数的解决方案,输出其中任意一个即可。 示例输入输出见题目描述中的"Example"部分。

加入题单

上一题 下一题 算法标签: