#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
string getString(char x) {
  string s(1, x);
  return s;
}
long long binaryToDecimal(string n) {
  string num = n;
  long long dec_value = 0;
  long long base = 1;
  long long len = num.length();
  for (long long i = len - 1; i >= 0; i--) {
    if (num[i] == '1') dec_value += base;
    base = base * 2;
  }
  return dec_value;
}
string decToBinary(long long n) {
  long long binaryNum[64];
  string s = "";
  long long i = 0;
  while (n > 0) {
    binaryNum[i] = n % 2;
    n = n / 2;
    i++;
  }
  for (int j = i - 1; j >= 0; j--) s += getString(char(binaryNum[j]));
  return s;
}
class Graph {
  int V;
  list<int>* adj;

 public:
  Graph(int V) {
    this->V = V;
    adj = new list<int>[V];
  }
  void addEdge(int s, int d);
  bool BFS(int s, int d);
};
void Graph::addEdge(int s, int d) {
  adj[s].push_back(d);
  adj[d].push_back(s);
}
bool Graph::BFS(int s, int d) {
  if (s == d) return true;
  bool* visited = new bool[V];
  for (int i = 0; i < V; i++) visited[i] = false;
  list<int> queue;
  visited[s] = true;
  queue.push_back(s);
  list<int>::iterator i;
  while (!queue.empty()) {
    s = queue.front();
    queue.pop_front();
    for (i = adj[s].begin(); i != adj[s].end(); ++i) {
      if (*i == d) return true;
      if (!visited[*i]) {
        visited[*i] = true;
        queue.push_back(*i);
      }
    }
  }
  return false;
}
bool isSafe(int i, int j, int M[][50], int row, int N) {
  if ((i < 0 || i >= row) || (j < 0 || j >= N) || M[i][j] == 0) return false;
  return true;
}
bool findPath(int M[][50], int row, int N) {
  int s, d;
  int V = row * N + 2;
  Graph g(V);
  int k = 1;
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < N; j++) {
      if (M[i][j] != 0) {
        if (isSafe(i, j + 1, M, row, N)) g.addEdge(k, k + 1);
        if (isSafe(i, j - 1, M, row, N)) g.addEdge(k, k - 1);
        if (j < N - 1 && isSafe(i + 1, j, M, row, N)) g.addEdge(k, k + N);
        if (i > 0 && isSafe(i - 1, j, M, row, N)) g.addEdge(k, k - N);
      }
      if (M[i][j] == 1) s = k;
      if (M[i][j] == 2) d = k;
      k++;
    }
  }
  return g.BFS(s, d);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int fe = 0, x = 0, count = 0;
    map<long long, long long> f;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] % k != 0) {
        f[-1 * (a[i] % k) + k]++;
        fe++;
      }
    }
    long long ma = 0;
    for (auto i : f) {
      long long v = (i.second - 1) * k + i.first + 1;
      ma = max(v, ma);
    }
    cout << ma << endl;
  }
  return 0;
}
