#C6055. Unique Array Balance

    ID: 49773 Type: Default 1000ms 256MiB

Unique Array Balance

Unique Array Balance

Given two arrays of integers in each test case, your task is to determine whether the arrays have the same set of unique integers. Two arrays are considered BALANCED if, after removing duplicates, both arrays contain exactly the same elements; otherwise, they are UNBALANCED.

For each test case:

  • The first number is an integer n representing the size of the first array.
  • The second line contains n space-separated integers.
  • The third number is an integer m representing the size of the second array.
  • The fourth line contains m space-separated integers.

Your solution should read input from stdin and output to stdout.

Note: If \(S_1\) and \(S_2\) are the unique sets of the two arrays respectively, then the arrays are balanced if and only if \(S_1 = S_2\).

inputFormat

The input begins with a single integer T (the number of test cases). Following that for each test case, there are 4 lines:

  1. An integer n denoting the number of elements in the first array.
  2. n space-separated integers representing the first array.
  3. An integer m denoting the number of elements in the second array.
  4. m space-separated integers representing the second array.

All input is read from stdin.

outputFormat

For each test case, output a single line containing either BALANCED if the unique elements of both arrays match, or UNBALANCED otherwise. All output should be written to stdout.

## sample
2
5
1 2 3 4 5
5
5 4 3 2 1
4
2 3 3 3
3
3 2 1
BALANCED

UNBALANCED

</p>