#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(NULL);
  ios::sync_with_stdio(0);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    long long a;
    map<long long, long long> m;
    long long result = 0;
    for (long long i = 0; i < n; ++i) {
      cin >> a;
      if (a % k != 0) {
        long long to_add = k - (a % k);
        long long moves = m[to_add] * k + to_add;
        result = max(result, moves);
        m[to_add]++;
      }
    }
    if (result > 0)
      cout << result + 1 << endl;
    else
      cout << 0 << endl;
  }
}
