#K80032. Three Sum Divisibility Checker

    ID: 35440 Type: Default 1000ms 256MiB

Three Sum Divisibility Checker

Three Sum Divisibility Checker

Given an integer array and an integer k, your task is to determine whether there exists any triplet of distinct elements in the array whose sum is divisible by k. In mathematical terms, you need to check if there exist three indices i, j, l (with i < j < l) such that:

\(a_i + a_j + a_l \equiv 0 \pmod{k}\)

If such a triplet exists, output YES; otherwise, output NO.

The problem may involve multiple test cases. Make sure your solution reads from STDIN and writes to STDOUT.

inputFormat

The input starts with an integer T (1 ≤ T ≤ 100), the number of test cases. Each test case is described as follows:

  • The first line contains two integers N and k (3 ≤ N ≤ 1000, 1 ≤ k ≤ 10^5), where N is the number of elements in the array and k is the divisor.
  • The second line contains N space-separated integers representing the array elements.

You should process each test case independently.

outputFormat

For each test case, output a single line containing either YES if there exists any three distinct elements whose sum is divisible by k, or NO otherwise.

## sample
1
5 3
1 2 3 4 5
YES