CF2104C.Card Game

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

Card Game

Alice and Bob are playing a game. They have nn cards numbered from 11 to nn. At the beginning of the game, some of these cards are given to Alice, and the rest are given to Bob.

Card with number ii beats card with number jj if and only if i>ji \gt j, with one exception: card 11 beats card nn.

The game continues as long as each player has at least one card. During each turn, the following occurs:

  1. Alice chooses one of her cards and places it face up on the table;
  2. Bob, seeing Alice's card, chooses one of his cards and places it face up on the table;
  3. if Alice's card beats Bob's card, both cards are taken by Alice. Otherwise, both cards are taken by Bob.

A player can use a card that they have taken during one of the previous turns.

The player who has no cards at the beginning of a turn loses. Determine who will win if both players play optimally.

Input

The first line contains a single integer tt (1t50001 \le t \le 5000) — the number of test cases.

Each test case consists of two lines:

  • the first line contains a single integer nn (2n502 \le n \le 50) — the number of cards;
  • the second line contains nn characters, each either A or B. If the ii-th character is A, then card number ii is initially given to Alice; otherwise, it is given to Bob.

Additional constraint on the input: in each test case, at least one card is initially given to Alice, and at least one card is initially given to Bob.

Output

For each test case, output Alice if Alice wins with optimal play, or Bob if Bob wins. It can be shown that if both players play optimally, the game will definitely end in a finite number of turns with one of the players winning.

Note

In the first test case, Alice has only one card, and Bob has only one card. Since Alice's card beats Bob's card, she wins after the first turn.

In the second test case, Alice has only one card, and Bob has only one card. Since Bob's card beats Alice's card, he wins after the first turn.

In the third test case, there are two possible game scenarios:

  • if Alice plays the card 11 on the first turn, Bob can respond with the card 22 and take both cards. Then, Alice has to play the card 33 on the second turn, and Bob will respond by playing the card 44. Then, he wins;
  • if Alice plays the card 33 on the first turn, Bob can respond with the card 44 and take both cards. Then, Alice has to play the card 11, and Bob can respond either with the card 22 or the card 33. Then, he wins.

In the fourth test case, there are two possible game scenarios:

  • if Alice plays the card 22 on the first turn, Bob can respond with the card 33 and take both cards. Then, Alice has to play the card 44 on the second turn, and Bob will respond by playing the card 11. Then, he wins;
  • if Alice plays the card 44 on the first turn, Bob can respond with the card 11 and take both cards. Then, Alice has to play the card 22, and Bob can respond either with the card 33 or the card 44. Then, he wins.

Samples

8
2
AB
2
BA
4
ABAB
4
BABA
3
BAA
5
AAAAB
5
BAAAB
6
BBBAAA
Alice
Bob
Bob
Bob
Alice
Alice
Bob
Alice

在线编程 IDE

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