logo AlgoBeat OnlineJudge
登录 注册

#215269. [USACO26JAN2] It's Mooin' Time IV B

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Bessie has a computer with a keyboard that only has two letters, M and O.

Bessie wants to type her favorite moo consisting of letters, each of which is either an M or an O. However, her computer has been hit with a virus. Every time she tries to type the letter O, every letter that she has typed so far flips, either from M to O or from O to M, before the O appears.

Is it possible for Bessie to type out her favorite moo?

Additionally, Bessie is given a parameter which is either or .

  • If , then Bessie only needs to determine whether it is possible to type out her favorite moo.
  • If , then Bessie also needs to give an example of a sequence of keystrokes to type so she can type out her favorite moo.

输入格式

The first line contains , the number of independent test cases () and (). The first line of each test case has ().

The second line of each test case has . It is guaranteed that no characters will appear in besides and .

The sum of across all test cases will not exceed .

输出格式

For each test case, output either one or two lines using the following procedure. If it is impossible for Bessie to type out , print on a single line.

Otherwise, on the first line print . Furthermore, if , on the second line, print a string of length , the characters in order that Bessie needs to type in order to type out her favorite moo. If there are multiple such strings, any will be accepted.

样例

样例输入 1

2 0
3
MOO
5
OOMOO

样例输出 1

YES
YES

样例输入 2

2 1
3
MOO
5
OOMOO

样例输出 2

YES
OMO
YES
MOOMO

数据范围与提示

As Bessie types out , this is how the letters change:

  • Before typing the first , Bessie has an empty string. Afterwards, she has the string .
  • After typing the first , the flips to , and then the is appended to form .
  • After typing the second , the flips to , and then the is appended to form .
  • After typing the second , Bessie has the string .
  • After typing the last , the string flips to , and then the is appended to form , as desired.

SCORING:

  • Inputs 3-4: .
  • Inputs 5-6: .
  • Inputs 7-9: .
  • Inputs 10-16: .