#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
long long int m, n, i, j, ans = 0, t;
long long int a[maxn], b[maxn];
map<long long int, long long int> mp;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long int i = 1; i <= n; i++) {
      cin >> a[i];
      a[i] = (m - a[i] % m) % m;
    }
    sort(a + 1, a + 1 + n);
    for (long long int i = 1; i <= n; i++) {
      b[i] = a[i];
      if (a[i] == 0)
        continue;
      else {
        if (a[i] != a[i - 1]) {
          mp[a[i]] = 1;
          b[i] = a[i];
        } else {
          b[i] = b[i - 1] + m;
          mp[b[i]] = 1;
        }
      }
    }
    sort(b + 1, b + 1 + n);
    if (b[n] != 0)
      ans = b[n] + 1;
    else
      ans = 0;
    cout << ans << endl;
  }
  return 0;
}
