#C10245. Balanced String Checker

    ID: 39429 Type: Default 1000ms 256MiB

Balanced String Checker

Balanced String Checker

Given a string consisting only of the characters 'a' and 'b', determine if the string is balanced. A string is considered balanced if the absolute difference between the number of 'a's and 'b's satisfies the condition \(|n_a - n_b| \le 1\). For each test case, output BALANCED if the condition holds, otherwise output UNBALANCED.

inputFormat

The first line contains an integer T representing the number of test cases. Each of the following T lines contains a non-empty string consisting only of characters 'a' and 'b'.

outputFormat

For each test case, output a single line: BALANCED if the string is balanced, or UNBALANCED otherwise.

## sample
4
abaa
aabb
abb
a
UNBALANCED

BALANCED BALANCED BALANCED

</p>