In Pigeland, Slay the Pig is the most popular roguelike game where players use card decks to challenge a boss called Evil Potato Lord.
The general game rules are as follows:
In this problem, for simplicity, we will only consider the effect of drawing cards. The rules for drawing cards are as follows:
Decks based on the key card Grand Finale are the most powerful deck in the game. Once this card is played, it will cause massive damage to all enemies and often leads to victory in the game. However, to play the Grand Finale card, there are strict conditions. That is, the player's draw pile must be empty, which means that all cards must either be played, discarded, or in the player's hand.
Bie-Bot is the smartest pig in Pigeland only after the Mysterious Oscar, and he is also playing a Grand Finale-based deck, which can contain the following four types of cards:
At the beginning of the game, Bie-Bot was lucky to have drawn the only one Grand Finale in his starting hand, and he also knows that each card in the draw pile from top to bottom. Now, his goal is to successfully play the Grand Finale card. Bie-Bot wants to know, under his optimal strategy, what is the minimum hand size limit $$$k$$$ required for him to achieve his goal. As the third smartest player in Pigeland, can you help him out?
More formally, you are given a string $$$S_{H}$$$ of length $$$n$$$ representing Bie-Bot's starting hand and a string $$$S_{P}$$$ of length $$$m$$$ representing the draw pile from top to bottom. Both strings consist of uppercase letters 'G', 'Q', 'B' and 'W', indicating that the card at the corresponding position in the starting hand or draw pile is Grand Finale, Quick Slash, Backflip, or Wound, respectively. Bie-Bot can use the cards in his hand according to the rules mentioned above. Please output the minimum hand size limit $$$k$$$ ($$$k \geq n$$$) such that Bie-Bot can finally play the Grand Finale or state that there is no such $$$k$$$.
There are multiple test cases. The first line of the input contains an integer $$$T$$$ indicating the number of test cases. For each test case:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 2500$$$) indicating the number of cards in Bie-Bot's starting hand and draw pile.
The second line contains a string $$$S_{H}$$$ of length $$$n$$$ to represent Bie-Bot's starting hand, consisting of uppercase letters 'G', 'Q', 'B', and 'W'. It's guaranteed that there is exactly one 'G' in $$$S_{H}$$$.
The third line of the input contains a string $$$S_{P}$$$ of length $$$m$$$ to represent Bie-Bot's draw pile from top to bottom, consisting of uppercase letters 'Q', 'B', and 'W'.
It is guaranteed that the sum of $$$(n + m)$$$ of all test cases will not exceed $$$5 \times 10^4$$$.
For each test case output one line containing one integer indicating the minimum hand size $$$k$$$ ($$$k \geq n$$$) that can lead to successfully playing Grand Finale, or IMPOSSIBLE if it can't be played.
22 6BGBQWBWW4 6GQBWWWWWQB
3 IMPOSSIBLE
We express the situation with "hand/deck" string. For the first sample test case, one optimal strategy is:
| Name |
|---|


