Popping Groups

No attempts yetTime limit2sMemory limit128 MB

Problem

You are given a string ss consisting only of the characters a and b. A group is a maximal run of consecutive identical characters. Any group gg whose length is at least 22 can be removed (popped) in its entirety; after removing it, the remaining left part and right part are concatenated into a new string. Repeat this process until the string becomes empty or no group of length at least 22 remains.

For example, s=s = babbbaaabb has five groups. You can turn it into the empty string as follows (the group in bold is the one being popped):

babbbaaabb → baaaabb → bbb → empty string

However, the following order fails to reach the empty string:

babbbaaabb → babbbaaa → baaaa → b

Given a string, write a program that decides whether it can be reduced to the empty string by popping groups in a suitable order.

Input

The first line contains the number of test cases TT. Each of the following lines contains one string made up of a and b. Each string has length between 11 and 2525 inclusive.

Output

For each test case, print 1 if the given string can be reduced to the empty string, or 0 otherwise, one per line.