#K66582. Balanced Ingredient Sets

    ID: 32452 Type: Default 1000ms 256MiB

Balanced Ingredient Sets

Balanced Ingredient Sets

You are given T test cases. In each test case, you are given two integers \(n\) and \(k\) followed by \(n\) integers representing ingredient quantities.

Your task is to determine whether it is possible to partition the ingredients into balanced sets such that the frequency of each unique ingredient is divisible by \(k\).
Formally, for each test case, if an ingredient appears \(f\) times, then \(f \bmod k = 0\) must hold. If this condition holds for every ingredient, print POSSIBLE; otherwise, print IMPOSSIBLE.

Input/Output: Read from standard input and write to standard output.

inputFormat

The first line contains an integer \(T\) denoting the number of test cases. Each test case consists of two lines:

  • The first line contains two integers \(n\) and \(k\), where \(n\) is the number of ingredients and \(k\) is the divisor for balancing.
  • The second line contains \(n\) integers representing the quantities of each ingredient.

outputFormat

For each test case, output a single line containing either POSSIBLE or IMPOSSIBLE depending on whether the quantities can be partitioned into balanced sets as described.

## sample
2
6 2
4 4 2 2 4 4
5 3
4 4 6 6 8
POSSIBLE

IMPOSSIBLE

</p>