403354: GYM101138 B Pen Pineapple Apple Pen
Description
PPAP, which stands for Pen Pineapple Apple Pen, is an unusual song and dance that went viral in the Internet recently. It's about merging a pen with either an apple or a pineapple, and then merging those together into more complicated structures.
A structure is either one of mentioned items (a pen, an apple or a pineapple) or a result of combining two structures. In the former case we say a structure is basic.
The size of a basic structure is 1. The size of any other structure is equal to the sum of sizes of two structures merged into this one.
Two structures can be merged if one of the following conditions holds true:
- Both structures are basic and exactly one of them is a pen.
- None of two structures are basic and their sizes are equal.
A structure can be represented by a string of length equal to the size of the structure. A basic structure is represented by "A" (if it's an apple) or by "P" (if it's a pen or a pineapple). When a structure represented by a string w1 and a structure represented by a string w2 are merged together, they create a structure represented by a string w1w2 (strings are concatenated). The order of two merged structures matters because w1w2 may be different that w2w1.
You are given T test cases, each with one string si consisting of characters 'A' and 'P'. Your task is to check whether it's possible to get a structure represented by such a string. Print "YES" or "NO" in a separate line, without the quotes.
InputThe first line of the input contains an integer T (1 ≤ T ≤ 10) — the number of test cases.
Each of the next T lines contains one string si (1 ≤ |si| ≤ 100), describing one test case. A string si consists of characters 'A' and 'P' only.
OutputFor each test case in a separate line print "YES" (without the quotes) if it's possible to get a structure represented by the given string, and "NO" otherwise (without the quotes).
ExampleInput4Output
PPAP
A
AAAA
PPAPP
YESNote
YES
NO
NO
In the first test case, one valid way is to merge a pen and a pineapple to get "PP", then merge an apple and a pen to get "AP", and finally merge two created structured in the order ("PP", "AP"). The final structure is represented by "PPAP", as required.