PivotOJ

Farmer John's Favorite Operation

시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 January SilverBOJ 33505

문제

It is another cold and boring day on Farmer John's farm. To pass the time, Farmer John has invented a fun leisure activity involving performing operations on an integer array.

Farmer John has an array aa of NN (1N21051 \leq N \leq 2 \cdot 10^5) non-negative integers and an integer MM (1M1091 \leq M \leq 10^9). Then, FJ will ask Bessie for an integer xx. In one operation, FJ can pick an index ii and subtract or add 11 to aia_i. FJ's boredom value is the minimum number of operations he must perform so that aixa_i-x is divisible by MM for all 1iN1 \leq i \leq N.

Among all possible xx, output FJ's minimum possible boredom value.

입력

The first line contains TT (1T101 \leq T \leq 10), the number of independent test cases to solve.

The first line of each test case contains NN and MM.

The second line of each test case contains a1,a2,...,aNa_1, a_2, ..., a_N (0ai1090 \leq a_i \leq 10^9).

It is guaranteed that the sum of NN over all test cases does not exceed 51055 \cdot 10^5.

출력

For each test case, output an integer on a new line containing FJ's minimum possible boredom value among all possible values of xx.

예제

예제 1

입력
2
5 9
15 12 18 3 8
3 69
1 988244353 998244853
출력
10
21
코드를 제출하려면 로그인하세요.