The cow cotillion is a fancy dance held every spring. During the dance, the cows (shown as ) and the bulls (shown as ) must bow to each other. Schematically, one properly bowing pair of cattle looks like this: .
Sometimes another pair of cattle sashays in between a bowing pair: .
In fact, sometimes even more cattle mix it up on the dance floor: (this line also includes a second bowing pair on the right). Quite complex arrangements can still be perfectly legal dance formations:

Farmer John has noticed that a stray heifer sometimes sneaks into a group and unbalances it: . This is strictly forbidden, and FJ wants to punish the interlopers.
FJ has written down the dance lines of as many as cows and wonders whether each line is properly balanced, that is, whether all the cattle in it can be split into properly bowing pairs in at least one way. He recorded only the direction in which each animal was bowing, without any extra spaces that might show which cow was bowing to which bull. For example, the illegal line from the previous paragraph is recorded as . Help him write a program that determines whether a dance line is legal.
FJ has recorded patterns p_i, each consisting only of the characters and and having length k_i~(1 \le k_i \le 200). Print "legal" for each pattern that can be split into properly bowing pairs, and "illegal" otherwise.
The first line contains an integer n~(1 \le n \le 1000). Each of the next lines contains an integer k_i followed by a space and a string p_i of k_i characters and .
For each pattern, print on a separate line "legal" if it is a legal bowing configuration, and "illegal" otherwise.
Example 1