from functools import lru_cache

def readints():
    return [int(obj) for obj in input().strip().split()]

class Solver:
    @lru_cache(maxsize=None)
    def f(self, last_item, total_sum):
        if last_item == 0:
            return {
                'value': 0,
                'items':  [],
            }

        ans = 0
        res = []
        for d in range(0, total_sum + 1):
            if d - self.t[last_item] >= 0 and d < self.d[last_item] and self.t[last_item] < self.d[last_item]:
                data = self.f(last_item - 1, d - self.t[last_item])
                if data['value'] + self.p[last_item] > ans:
                    ans = data['value'] + self.p[last_item]
                    res = data['items'] + [last_item]

            data = self.f(last_item - 1, d)
            if data['value'] > ans:
                ans = data['value']
                res = data['items']

        return {
            'value': ans,
            'items': res,
        }

    def main(self):
        n = readints()[0]
        self.t, self.d, self.p = [], [], []
        for i in range(n):
            t1, d1, p1 = readints()
            self.t.append(t1)
            self.d.append(d1)
            self.p.append(p1)
        triples = zip(self.t, self.d, self.p, range(1, n+1))
        triples = sorted(triples, key=lambda x: x[1])
        self.t, self.d, self.p, self.indexes = [0], [0], [0], []
        for i in range(n):
            self.t.append(triples[i][0])
            self.d.append(triples[i][1])
            self.p.append(triples[i][2])
            self.indexes.append(triples[i][3])

        ans = 0
        res = []
        for i in range(max(self.d) + 1):
            data = self.f(n, i)
            if data['value'] > ans:
                ans = data['value']
                res = data['items']

        print(ans)
        print(len(res))
        print(' '.join(str(self.indexes[item - 1]) for item in res))

Solver().main()


from functools import lru_cache

def readints():
    return [int(obj) for obj in input().strip().split()]

class Solver:
    def main(self):
        n = readints()[0]
        self.t, self.d, self.p = [], [], []
        for i in range(n):
            t1, d1, p1 = readints()
            self.t.append(t1)
            self.d.append(d1)
            self.p.append(p1)

        self.backtrack = []
        sd = max(self.d) + 1
        for i in range(n+1):
            self.backtrack.append([])
            for j in range(sd):
                self.backtrack[i].append(0)

        triples = zip(self.t, self.d, self.p, range(1, n+1))
        triples = sorted(triples, key=lambda x: x[1])
        self.t, self.d, self.p, self.indexes = [0], [0], [0], []
        for i in range(n):
            self.t.append(triples[i][0])
            self.d.append(triples[i][1])
            self.p.append(triples[i][2])
            self.indexes.append(triples[i][3])

        self.f = []
        for i in range(n+1):
            self.f.append([])
            for j in range(sd):
                self.f[i].append(0)

        for i in range(1, n+1):
            for d in range(sd):
                if d - self.t[i] >= 0 and d < self.d[i] and self.t[i] < self.d[i]:
                    data = self.f[i - 1][d - self.t[i]]
                    if data + self.p[i] > self.f[i][d]:
                        self.f[i][d] = data + self.p[i]
                        self.backtrack[i][d] = i

                data = self.f[i - 1][d]
                if data > self.f[i][d]:
                    self.f[i][d] = data
                    self.backtrack[i][d] = 0

        ans = 0
        res = []
        best = None
        for i in range(sd):
            data = self.f[n][i]
            if data > ans:
                ans = data
                best = (n, i)

        if best is None:
            print('0\n0\n')
            return

        i = best[0]
        s = best[1]
        while i > 0:
            if self.backtrack[i][s] != 0:
                res.append(self.backtrack[i][s])
                s -= self.t[self.backtrack[i][s]]
            i -= 1

        print(ans)
        print(len(res))
        print(' '.join(str(self.indexes[item - 1]) for item in reversed(res)))

Solver().main()


from functools import lru_cache

def readints():
    return [int(obj) for obj in input().strip().split()]

class Solver:
    def main(self):
        n = readints()[0]
        self.t, self.d, self.p = [], [], []
        for i in range(n):
            t1, d1, p1 = readints()
            self.t.append(t1)
            self.d.append(d1)
            self.p.append(p1)

        self.backtrack = []
        sd = sum(self.d) + 1
        for i in range(n+1):
            self.backtrack.append([])
            for j in range(sd):
                self.backtrack[i].append(0)

        triples = zip(self.t, self.d, self.p, range(1, n+1))
        triples = sorted(triples, key=lambda x: x[1])
        self.t, self.d, self.p, self.indexes = [0], [0], [0], []
        for i in range(n):
            self.t.append(triples[i][0])
            self.d.append(triples[i][1])
            self.p.append(triples[i][2])
            self.indexes.append(triples[i][3])

        self.f = []
        for i in range(n+1):
            self.f.append([])
            for j in range(sd+1):
                self.f[i].append(0)

        for i in range(1, n+1):
            for d in range(sd):
                if d - self.t[i] >= 0 and d < self.d[i] and self.t[i] < self.d[i]:
                    data = self.f[i - 1][d - self.t[i]]
                    if data + self.p[i] > self.f[i][d]:
                        self.f[i][d] = data + self.p[i]
                        self.backtrack[i][d] = i

                data = self.f[i - 1][d]
                if data > self.f[i][d]:
                    self.f[i][d] = data
                    self.backtrack[i][d] = 0

        ans = 0
        res = []
        best = None
        for i in range(sum(self.d) + 1):
            data = self.f[n][i]
            if data > ans:
                ans = data
                best = (n, i)

        # for i in range(n+1):
        #     print(self.backtrack[i])

        i = best[0]
        s = best[1]
        while i > 0:
            if self.backtrack[i][s] != 0:
                res.append(self.backtrack[i][s])
                s -= self.t[self.backtrack[i][s]]
            i -= 1

        print(ans)
        print(len(res))
        print(' '.join(str(self.indexes[item - 1]) for item in reversed(res)))

Solver().main()


#include <bits/stdc++.h>
using namespace std;

#define ll long long int

bool cmp(pair<string, int>& a,
         pair<string, int>& b)
{
    if (a.second == b.second) {
        return a.first > b.first;
    }
    return a.second > b.second;
}

void sol(map<ll, ll>& M)
{

    vector<pair<ll, ll> > A;

    for (auto& it : M) {
        A.push_back(it);
    }

    sort(A.begin(), A.end(), cmp);

    // for (auto& it : A) {
    //     cout << it.first << ' '
    //          << it.second << endl;
    // }

    let ans= A[0].first
    ans--;
    cout<< ans+(k*(ans-1))+1 <<endl;
}

int main() {
	int t;
	cin>>t;

	while(t--){
	    ll n,k,a;
	    cin>>n>>k;
	    map<ll,ll> mp;
	    for (int i = 0; i < n; i++) {
	        cin>>a;
	        mp[k-(a%k)]++;
	    }
	    sol(mp);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

long long n, k;
unordered_map<int, int> rem;

int main()
{
	int z;
	cin>>z;
	while(z--)
	{
		rem.clear();
		long long x;
		cin>>n>>k;
		long long ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<long long>
#define pb push_back

long long n, k;
unordered_map<long long, long long> rem;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int z;
	cin>>z;
	vi cl;
	while(z--)
	{
		for(auto it : cl)
			rem[it] = 0;
		cl.clear();
		long long x;
		cin>>n>>k;
		long long ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			if(rem[x%k] == 0)
				cl.push_back(x%k);
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

int n, k;
unordered_map<int, int> rem;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int z;
	cin>>z;
	vi cl;
	while(z--)
	{
		for(auto it : cl)
			rem[it] = 0;
		cl.clear();
		int x;
		cin>>n>>k;
		int ans = 0;
		int big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			if(rem[x%k] == 0)
				cl.push_back(x%k);
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(int)ans*(int)k + big + (int)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

long long n, k;
unordered_map<int, int> rem;

int main()
{
	int z;
	cin>>z;
	vector<int> t;
	while(z--)
	{
		rem.clear();
		t.clear();
		long long x;
		cin>>n>>k;
		int ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

long long n, k;
unordered_map<int, int> rem;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int z;
	cin>>z;
	while(z--)
	{
		rem.clear();
		long long x;
		cin>>n>>k;
		long long ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			rem[x%k]++;
			if(rem[x%k]-1 >= ans)
			{
				ans = rem[x%k]-1;
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

long long n, k;
unordered_map<int, int> rem;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int z;
	cin>>z;
	vi cl;
	while(z--)
	{
		for(auto it : cl)
			rem[it] = 0;
		cl.clear();
		long long x;
		cin>>n>>k;
		long long ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			if(rem[x%k] == 0)
				cl.push_back(x%k);
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vivi;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll z, ans, k, n;
	vi t;
	cin >> z;
	while(z--)
	{
		cin >> n >> k;
		t = vi(n);
		ans = 0;
		map<int, ll> res;
		for(int i=0; i<n; i++)
		{
			cin >> t[i];
			res[(k-t[i]%k)%k]++;
		}
		for(auto it : res)
			ans = max(ans, (it.se-1)*k + it.fi+1);
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back

long long n, k;
unordered_map<int, int> rem;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int z;
	cin>>z;
	while(z--)
	{
		rem.clear();
		long long x;
		cin>>n>>k;
		long long ans = 0;
		long long big = 0;
		for(int i=0; i<n; i++)
		{
			cin>>x;
			if(x%k == 0)continue;
			rem[x%k]++;
			if(rem[x%k]-1 > ans)
			{
				ans = rem[x%k]-1;
				big = k - x%k;
			}
			if(rem[x%k]-1 == ans)
			{
				big = max(big, k - x%k);
			}
		}
		if(big == 0 && ans == 0)
		{
			cout<<0<<"\n";
		}
		else
		{
			cout<<(long long)ans*(long long)k + big + (long long)1<<"\n";
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vivi;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll z, ans, k, n;
	vi t;
	cin >> z;
	while(z--)
	{
		cin >> n >> k;
		t = vi(n);
		ans = 0;
		map<int, ll> res;
		for(int i=0; i<n; i++)
		{
			cin >> t[i];
			res[(k-t[i]%k)%k]++;
		}
		for(auto it : res)
		{
			if(it.fi == 0)
				continue;
			ans = max(ans, (it.se-1)*k + it.fi+1);
		}
		cout << ans << "\n";
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        long long n, k;
        cin>>n>>k;
        long long arr[n];
        vector<long long> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }
        sort(rem.begin(), rem.end());
        long long cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(n==1)
        {
            cout<<rem[0]+1;
            continue;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        long long n, k;
        cin>>n>>k;
        long long arr[n];
        vector<long long> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }

        if(n==1)
        {
            if(rem[0]==0)
                cout<<"0"<<endl;
            else
                cout<<rem[0]+1<<endl;
            continue;
        }

        sort(rem.begin(), rem.end());
        long long cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        long long n, k;
        cin>>n>>k;
        long long arr[n];
        vector<long long> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }
        /*
        if(n==1)
        {
            cout<<rem[0]+1<<endl;
            continue;
        }
        */
        sort(rem.begin(), rem.end());
        long long cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        long long n, k;
        cin>>n>>k;
        long long arr[n];
        vector<long long> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }
        if(n==1)
        {
            cout<<rem[0]+1<<endl;
            continue;
        }
        sort(rem.begin(), rem.end());
        long long cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        long long n, k;
        cin>>n>>k;
        long long arr[n];
        vector<long long> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }
        sort(rem.begin(), rem.end());
        long long cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int i=0; i<t; i++)
    {
        int n, k;
        cin>>n>>k;
        int arr[n];
        vector<int> rem;
        for(int j=0; j<n; j++)
        {
            cin>>arr[j];
            if(arr[j]%k==0)
                rem.push_back(0);
            else
                rem.push_back(k-arr[j]%k);
        }
        sort(rem.begin(), rem.end());
        int cur=rem[0], curcount=1, maxcount=0, x;
        for(int j=1; j<n; j++)
        {
            if(rem[j]==0)
                continue;
            if(rem[j]==cur)
                curcount++;
            else
            {
                cur=rem[j];
                curcount=1;
            }
            if(curcount>=maxcount)
            {
                maxcount=curcount;
                x=cur;
            }
            //cout<<"In at j= "<<j<<", rem[j]= "<<rem[j]<<", cur= "<<cur<<", curcount= "<<curcount<<", maxcount= "<<maxcount<<", x="<<x<<endl;
        }
        if(maxcount==1)
            cout<<rem[n-1]+1<<endl;
        else if(maxcount==0)
            cout<<"0"<<endl;
        else
            cout<<((maxcount-1)*k)+x+1<<endl;
    }
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
    	ll res = 0;
		int maxv = -1,pos = -1;
		int n,k;scanf("%d%d",&n,&k);
		vector<int> cnt(40,0);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			for(int i = 1;i <= n;++i)
			{
				if(a[i] % k == 0)	continue;
				++cnt[k - a[i] % k];
				maxv = max(maxv,cnt[k - a[i] % k]);
			}
		}
    	if(maxv == -1)	printf("0\n");
    	else
    	{
    		for(int i = 0;i < 40;++i)
    			if(cnt[i] == maxv)
    			{
    				res = (maxv - 1) * k + i + 1;
    			}
    	}
    	printf("%lld\n",res);
    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
    	ll res = 0;
		int maxv = -1,pos = -1;
		int n,k;scanf("%d%d",&n,&k);
		vector<int> cnt(40,0);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			for(int i = 1;i <= n;++i)
			{
				if(a[i] % k == 0)	continue;
				++cnt[k - a[i] % k];
				maxv = max(maxv,cnt[k - a[i] % k]);
			}
		}
    	if(maxv == -1)	printf("0\n");
    	else
    	{
    		for(int i = 0;i < 40;++i)
    			if(cnt[i] == maxv)
    			{
    				res = (maxv - 1) * k + i + 1;
    			}
    		printf("%lld\n",res);
    	}
    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
		int n,k;scanf("%d%d",&n,&k);
		vector<int> cnt(40,0);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			for(int i = 1;i <= n;++i)
			{
				int c = a[i] % k;
				++cnt[c];
			}
			ll res = 0;
			int maxv = -1,pos = -1;
			for(int i = 1;i < k;++i)
			{
				// cout << i << " " << cnt[i] << endl;
				if(cnt[i] > maxv)
				{
					maxv = cnt[i];
					pos = i;
				}
				// cout << " " << res << endl;
			}
			// cout << k << " " << maxv << endl;
			// cout << maxv << " " << pos << endl;
	    	if(maxv == -1)	printf("0\n");
	    	else printf("%d\n",(maxv - 1) * k + k - pos + 1);
		}

    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
		int n,k;scanf("%d%d",&n,&k);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			map<int,int> cnt;
			for(int i = 1;i <= n;++i)
			{
				if(a[i] % k == 0)	continue;
				int c = a[i] % k;
				++cnt[c];
			}
			ll res = 0;
			int maxv = -1,pos = -1;
			for(map<int,int>::iterator i = cnt.begin();i != cnt.end();++i)
			{
				if((*i).second > maxv)
				{
					maxv = (*i).second;
					pos = (*i).first;
				}
			}
			// cout << k << " " << maxv << endl;
			// cout << maxv << " " << pos << endl;
	    	if(maxv == -1)	printf("0\n");
	    	else printf("%lld\n",(1ll * maxv - 1) * k + k - pos + 1);
		}

    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
		int n,k;scanf("%d%d",&n,&k);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			map<int,int> cnt;
			for(int i = 1;i <= n;++i)
			{
				if(a[i] % k == 0)	continue;
				int c = a[i] % k;
				++cnt[c];
			}
			ll res = 0;
			int maxv = -1,pos = -1;
			for(map<int,int>::iterator i = cnt.begin();i != cnt.end();++i)
			{
				if((*i).second > maxv)
				{
					maxv = (*i).second;
					pos = (*i).first;
				}
			}
			// cout << k << " " << maxv << endl;
			// cout << maxv << " " << pos << endl;
	    	if(maxv == -1)	printf("0\n");
	    	else printf("%d\n",(maxv - 1) * k + k - pos + 1);
		}

    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
		int n,k;scanf("%d%d",&n,&k);
		vector<int> cnt(40,0);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			for(int i = 1;i <= n;++i)
			{
				int c = a[i] % k;
				++cnt[c];
			}
		}
		ll res = 0;
		int maxv = -1,pos = -1;
		for(int i = 1;i < k;++i)
		{
			// cout << i << " " << cnt[i] << endl;
			if(cnt[i] > maxv)
			{
				maxv = cnt[i];
				pos = i;
			}
			// cout << " " << res << endl;
		}
		// cout << k << " " << maxv << endl;
		// cout << maxv << " " << pos << endl;
    	if(maxv == -1)	printf("0\n");
    	else printf("%d\n",(maxv - 1) * k + k - pos + 1);
    }
    return 0;
}


// Problem : D. Zero Remainder Array
// Contest : Codeforces - Codeforces Round #653 (Div. 3)
// URL : https://codeforces.ml/contest/1374/problem/D
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N];
ll qpow(int a,int b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)	res = (res * a);
		a *= a;
		b >>= 1;
	}
	return res;
}
int main()
{
    int T;scanf("%d",&T);
    while(T--)
    {
    	ll res = 0;
		int maxv = -1,pos = -1;
		int n,k;scanf("%d%d",&n,&k);
		vector<int> cnt(40,0);
		for(int i = 1;i <= n;++i)	scanf("%d",&a[i]);
		if(k == 1)	printf("0\n");
		else
		{
			for(int i = 1;i <= n;++i)
			{
				if(a[i] % k == 0)	continue;
				++cnt[k - a[i] % k];
				maxv = max(maxv,cnt[k - a[i] % k]);
			}
			if(maxv == -1)	printf("0\n");
	    	else
	    	{
	    		for(int i = 0;i < 40;++i)
	    			if(cnt[i] == maxv)
	    			{
	    				res = (maxv - 1) * k + i + 1;
	    			}
	    		printf("%lld\n",res);
	    	}
		}

    }
    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

ll b[N],cnt = 0;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		memset(b,0,sizeof(b)); cnt = 0;
		ll n,k; scanf("%lld%lld",&n,&k);
		ll ma = 0,la = -1;
		for(ll i=1;i<=n;i++)
		{
			ll a; scanf("%lld",&a);
			if(a % k > 0)
			{
				ll p = (k - (a % k));
				b[cnt++] = p;
			}
		}
		sort(b,b+cnt);
		ll last = b[0],m = 0;
		for(ll i=1;i<cnt;i++)
		{
			if(b[i] == last) m++;
			else
			{
				if(m >= ma)
				{
					ma = m;
					la = last;
				}
				m = 0;
				last = b[i];
			}
		}
		if(m >= ma)
		{
			ma = m;
			la = last;
		}
		ma = ma*k+la+1;
		printf("%lld\n",cnt?ma:0);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		unordered_map<int,int> mp;
		int n,k; scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			int a; scanf("%d",&a);
			ll p = (k - a);
	        p %= k;
	        p += k;
	        p %= k;
			if(p != 0) mp[p] ++;
		}
		ll ma = 0;
		for(auto i : mp)
		{
			ll p = i.second - 1;
			ma = max(ma,p*k+i.first+1);
		}
		printf("%lld\n",ma);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		unordered_map<ll,ll> mp;
		int n,k; scanf("%d%d",&n,&k);
		ll ma = 0;
		for(int i=1;i<=n;i++)
		{
			int a; scanf("%d",&a);
			if(a % k != 0)
			{
				int p = (k - (a % k));
				ma = max(ma,mp[p]*k+p+1);
				mp[p] ++;
			}
		}
		printf("%lld\n",ma);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		map<ll,ll> mp;
		int n,k; scanf("%d%d",&n,&k);
		ll ma = 0;
		for(int i=1;i<=n;i++)
		{
			int a; scanf("%d",&a);
			if(a % k != 0)
			{
				int p = (k - (a % k));
				ma = max(ma,mp[p]*k+p+1);
				mp[p] ++;
			}
		}
		printf("%lld\n",ma);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		unordered_map<int,int> mp;
		int n,k; scanf("%d%d",&n,&k);
		ll ma = 0,la = -1;
		for(int i=1;i<=n;i++)
		{
			int a; scanf("%d",&a);
			if(a % k != 0)
			{
				int p = (k - (a % k));
				mp[p] ++;
				if(mp[p] == ma && p > la)
				{
					la = p;
					ma = mp[p];
				}
				else if(mp[p] > ma)
				{
					la = p;
					ma = mp[p];
				}
			}
		}
		ma = (ma-1)*k+la+1;
		printf("%lld\n",ma>0?ma:0);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		unordered_map<ll,ll> mp;
		ll n,k; scanf("%lld%lld",&n,&k);
		ll ma = 0,la = -1;
		for(ll i=1;i<=n;i++)
		{
			ll a; scanf("%lld",&a);
			if(a % k > 0)
			{
				ll p = (k - (a % k));
				mp[p] ++;
				if(mp[p] == ma && p > la)
				{
					la = p;
					ma = mp[p];
				}
				else if(mp[p] > ma)
				{
					la = p;
					ma = mp[p];
				}
			}
		}
		ma = (ma-1)*k+la+1;
		printf("%lld\n",ma>0?ma:0);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

vector<int> ve;
unordered_map<int,int> mp;
int main(){
	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; cin>>tt;
	while(tt --)
	{
		ve.clear(); mp.clear();
		int n,k; cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			int a; cin>>a;
			if(a % k != 0)
			{
				int p = (k - (a % k));
				if(mp[p] == 0)  ve.push_back(p);
				mp[p] ++;
			}
		}
		ll ma = 0;
		for(int i=0;i<(int)ve.size();i++)
		{
			ll p = mp[ve[i]]-1;
			ma = max(ma,p*k+ve[i]+1);
		}
		cout<<ma<<endl;
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

unordered_map<ll,ll> mp;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		mp.clear();
		ll n,k; scanf("%lld%lld",&n,&k);
		ll ma = 0,la = -1;
		for(ll i=1;i<=n;i++)
		{
			ll a; scanf("%lld",&a);
			if(a % k > 0)
			{
				ll p = (k - (a % k));
				mp[p] ++;
				if(mp[p] == ma && p > la)
				{
					la = p;
					ma = mp[p];
				}
				else if(mp[p] > ma)
				{
					la = p;
					ma = mp[p];
				}
			}
		}
		ma = (ma-1)*k+la+1;
		printf("%lld\n",ma>0?ma:0);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

vector<int> ve;
unordered_map<int,int> mp;
int main(){
	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; cin>>tt;
	while(tt --)
	{
		ve.clear(); mp.clear();
		int n,k; cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			int a; cin>>a;
			if(a % k != 0)
			{
				int p = (k - (a % k));
				ve.push_back(p);
			}
		}
		ll ma = 0;
		for(int i=0;i<(int)ve.size();i++)
		{
			for(int j = 0;;j++)
			{
				ll p = j*k + ve[i];
				if(!mp[p])
				{
					mp[p] = 1;
					ma = max(ma,p+1);
					break;
				}
			}
		}
		cout<<ma<<endl;
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
//	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; scanf("%d",&tt);
	while(tt --)
	{
		unordered_map<int,int> mp;
		int n,k; scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++)
		{
			int a; scanf("%d",&a);
			if(a % k != 0)
			{
				int p = (k - (a % k));
				mp[p] ++;
			}
		}
		ll ma = 0;
		for(auto i : mp)
		{
			ll p = i.second - 1;
			ma = max(ma,p*k+i.first+1);
		}
		printf("%lld\n",ma);
	}

    return 0;
}


#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int mod = 1e9+9;
const int N = 200010;

int main(){
	IOS;
	#ifdef ddgo
		freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin);
	#endif

	int tt; cin>>tt;
	while(tt --)
	{
		unordered_map<int,int> mp;
		int n,k; cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			int a; cin>>a;
			if(a % k != 0)
			{
				int p = (k - (a % k));
				mp[p] ++;
			}
		}
		ll ma = 0;
		for(auto i : mp)
		{
			ll p = i.second - 1;
			ma = max(ma,p*k+i.first+1);
		}
		cout<<ma<<endl;
	}

    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        long long dp[n];

        int i=0;
        while(i<n&&a[i]==0){
            dp[i]=0;
            i++;
        }
        if(i<n){
            dp[i]=a[i]+1;
            i++;
            long long c=1;
            for(int j=i;j<n;j++){
                if(a[j]==a[j-1]){
                    dp[j]=c*k+1+a[j];
                    c++;
                }
                else{
                    c=0;
                    dp[j]=c*k+1+a[j];
                    c++;
                }
            }
        }
        long long max=0;
        for(int j=0;j<n;j++){
            if(dp[j]>max){
                max=dp[j];
            }
        }

        printf("%lld\n",max);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=k-(a[i]%k);
        }
        sort(a,a+n);
        int x=0;
        for(int i=0;i<n;i++){
            if(a[i]==0){
                continue;
            }
            x++;
        }
        x=x+a[n-1];
        printf("%d\n",x);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        int x=0;
        for(int i=0;i<n;i++){
            if(a[i]==0){
                continue;
            }
            x++;
        }
        x=x+a[n-1];
        printf("%d\n",x);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        long long dp[n];

        int i=0;
        while(i<n&&a[i]==0){
            dp[i]=0;
            i++;
        }
        if(i<n){
            dp[i]=a[i]+1;
            i++;
            long long c=1;
            for(int j=i;j<n;j++){
                if(a[j]==a[j-1]){
                    dp[j]=c*k+1+a[j];
                    c++;
                }
                else{
                    c=0;
                    dp[j]=c*k+1+a[j];
                    c++;
                }
            }
        }
        long long max=0;
        for(int j=0;j<n;j++){
            if(dp[j]>max){
                max=dp[j];
            }
        }

        printf("%ld\n",max);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        long long dp[n];

        int i=0;
        while(i<n&&a[i]==0){
            dp[i]=0;
            i++;
        }
        if(i<n){
            dp[i]=a[i]+1;
            i++;
            long long c=1;
            for(int j=i;j<n;j++){
                if(a[i]==a[i-1]){
                    dp[i]=k*c+1+a[i];
                    c++;
                }
                else{
                    c=0;
                    dp[i]=k*c+1+a[i];
                    c++;
                }
            }
        }
        long long max=0;
        for(int i=0;i<n;i++){
            if(dp[i]>max){
                max=dp[i];
            }
        }

        printf("%ld\n",max);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        long long dp[n];

        int i=0;
        while(i<n&&a[i]==0){
            dp[i]=0;
            i++;
        }
        if(i<n){
            dp[i]=a[i]+1;
            i++;
            long long c=1;
            for(int j=i;j<n;j++){
                if(a[i]==a[i-1]){
                    dp[i]=k*c+1+a[i];
                    c++;
                }
                else{
                    c=0;
                    dp[i]=k*c+1+a[i];
                    c++;
                }
            }
        }
        long long max=0;
        for(int i=0;i<n;i++){
            if(dp[i]>max){
                max=dp[i];
            }
        }

        printf("%ld\n",maxx);
    }
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            a[i]=(k-(a[i]%k))%k;
        }
        sort(a,a+n);
        long long dp[n];

        int i=0;
        while(i<n&&a[i]==0){
            dp[i]=0;
            i++;
        }
        if(i<n){
            dp[i]=a[i]+1;
            i++;
            long long c=1;
            for(int j=i;j<n;j++){
                if(a[j]==a[j-1]){
                    dp[j]=k*c+1+a[j];
                    c++;
                }
                else{
                    c=0;
                    dp[j]=k*c+1+a[j];
                    c++;
                }
            }
        }
        long long max=0;
        for(int j=0;j<n;j++){
            if(dp[j]>max){
                max=dp[j];
            }
        }

        printf("%ld\n",max);
    }
}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	map<int,int> freq ;
	int maxfreq = 0 ;
	ll maxdiff = 0 ;

	bool alldiv = true ;

	for( int i = 0 ; i < n ; i++ )
	{
		if( a[i] % k != 0 )
		{
			alldiv = false ;
			int diff = k - (a[i] % k ) ;

			auto iter = freq.find( diff ) ;

			if( iter == freq.end() )
				freq[diff] = 1 ;
			else
				freq[diff]++ ;

			// Get max freq
			if( freq[diff] > maxfreq )
			{
				maxfreq = freq[diff] ;
				maxdiff = diff ;
			}
		}
	}

	ll steps = 0 ;

	if( !alldiv )
		steps  = k * 1ll * (maxfreq-1) + (maxdiff+1) ;

	cout << steps << "\n" ;
}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	map<int,int> freq ;
	int maxfreq = 0 ;
	ll maxdiff = 0 ;

	bool alldiv = true ;

	for( int i = 0 ; i < n ; i++ )
	{
		if( a[i] % k != 0 )
		{
			alldiv = false ;
			int diff = k - (a[i] % k ) ;

			auto iter = freq.find( diff ) ;

			if( iter == freq.end() )
				freq[diff] = 1 ;
			else
				freq[diff]++ ;

			// Get max freq
			if( freq[diff] > maxfreq )
			{
				maxfreq = freq[diff] ;
				maxdiff = diff ;
			}
		}

	}

	ll steps = 0 ;

	if( !alldiv )
		steps = k * ( maxfreq-1) + (maxdiff + 1) ;

	cout << steps << "\n" ;
}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	map<int,int> freq ;
	int maxfreq = 0 ;
	ll maxdiff = 0 ;

	for( int i = 0 ; i < n ; i++ )
	{
		if( a[i] % k != 0 )
		{
			int diff = k - (a[i] % k ) ;

			auto iter = freq.find( diff ) ;

			if( iter == freq.end() )
				freq[diff] = 1 ;
			else
				freq[diff]++ ;

			// Get max freq
			if( freq[diff] > maxfreq )
			{
				maxfreq = freq[diff] ;
				maxdiff = diff ;
			}
		}
	}

	ll steps = 0 ;

	auto iter = freq.begin() ;

	for( ; iter != freq.end() ; iter++ )
	{
		if( iter -> second == maxfreq )
			steps = k * (iter->second -1) + (iter->first +1) ;
	}

	cout << steps << "\n" ;
}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		// Calculate diff for each
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] % k == 0 )
				a[i] = 0 ;

			else if( a[i] < k )
				a[i] = k - a[i] ;

			else
			{
				int m = a[i] / k ;
				a[i] = (m+1) * k - a[i] ;
			}
		}

		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			auto iter = freq.find( a[i] ) ;

			if( iter == freq.end() )
				freq.insert( pair<int,int>( a[i], 1 ) ) ;
			else
				iter-> second += 1 ;
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;

	for( int i = 1 ; i < n && allsame ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;
	}

	// If all are same
	if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			auto iter = freq.find( a[i] ) ;

			if( iter == freq.end() )
				freq.insert( pair<int,int>( a[i], 1 ) ) ;
			else
				iter-> second += 1 ;
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = abs (k - a[0] );
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		// Calculate diff for each
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] % k == 0 )
				a[i] = 0 ;

			else if( a[i] < k )
				a[i] = k - a[i] ;

			else
			{
				int m = a[i] / k ;
				a[i] = (m+1) * k - a[i] ;
			}
		}

		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] != 0 )
			{
				auto iter = freq.find( a[i] ) ;

				if( iter == freq.end() )
					freq.insert( pair<int,int>( a[i], 1 ) ) ;
				else
					iter-> second += 1 ;
			}
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq && iter -> first != 0 )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		// Calculate diff for each
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] % k == 0 )
				a[i] = 0 ;

			else if( a[i] < k )
				a[i] = k - a[i] ;

			else
			{
				int m = a[i] / k ;
				a[i] = (m+1) * k - a[i] ;
			}
		}

		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] != 0 )
			{
				auto iter = freq.find( a[i] ) ;

				if( iter == freq.end() )
					freq.insert( pair<int,int>( a[i], 1 ) ) ;
				else
					iter-> second += 1 ;
			}
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq && iter -> first != 0 )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] != a[n-1] )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			auto iter = freq.find( a[i] ) ;

			if( iter == freq.end() )
				freq.insert( pair<int,int>( a[i], 1 ) ) ;
			else
				iter-> second += 1 ;
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	map<int,int> freq ;
	int maxfreq = 0 ;
	ll maxdiff = 0 ;

	bool alldiv = true ;

	for( int i = 0 ; i < n ; i++ )
	{
		if( a[i] % k != 0 )
		{
			alldiv = false ;
			int diff = k - (a[i] % k ) ;

			auto iter = freq.find( diff ) ;

			if( iter == freq.end() )
				freq[diff] = 1 ;
			else
				freq[diff]++ ;

			// Get max freq
			if( freq[diff] > maxfreq )
			{
				maxfreq = freq[diff] ;
				maxdiff = diff ;
			}
		}

	}

	ll steps = 0 ;

	if( !alldiv )
		steps = k * ( maxfreq-1) + (maxdiff + 1 ) ;

	cout << steps << "\n" ;
}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = 0 ;

		if( a[0] % k == 0 )
			diff = 0 ;

		else if( a[0] < k )
			diff = k - a[0] ;

		else
		{
			int m = a[0] / k ;
			diff = (m+1) * k - a[0] ;
		}

		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		// Calculate diff for each
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] % k == 0 )
				a[i] = 0 ;

			else if( a[i] < k )
				a[i] = k - a[i] ;

			else
			{
				int m = a[i] / k ;
				a[i] = (m+1) * k - a[i] ;
			}
		}

		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			if( a[i] != 0 )
			{
				auto iter = freq.find( a[i] ) ;

				if( iter == freq.end() )
					freq.insert( pair<int,int>( a[i], 1 ) ) ;
				else
					iter-> second += 1 ;
			}
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq && iter -> first != 0 )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n && allsame ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			auto iter = freq.find( a[i] ) ;

			if( iter == freq.end() )
				freq.insert( pair<int,int>( a[i], 1 ) ) ;
			else
				iter-> second += 1 ;
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	// Check if all are same
	bool allsame = true ;
	bool alldiv = true ;

	for( int i = 1 ; i < n ; i++ )
	{
		if( a[i] != a[i-1] )
			allsame = false ;

		if( a[i] % k != 0 )
			alldiv = false ;
	}

	if( alldiv )
	{
		if( a[0] % k != 0 )
			alldiv = false ;
	}

	// IF all are already divisible
	if( alldiv )
	{
		cout << "0\n" ;
	}

	// If all are same
	else if( allsame )
	{
		int diff = k - a[0] ;
		diff++ ;

		int steps = diff + (n-1) * k ;

		cout << steps << "\n" ;
	}
	else
	{
		map<int,int> freq ;

		// Store frequencies of elements
		for( int i = 0 ; i < n ; i++ )
		{
			auto iter = freq.find( a[i] ) ;

			if( iter == freq.end() )
				freq.insert( pair<int,int>( a[i], 1 ) ) ;
			else
				iter-> second += 1 ;
		}

		// Find max freq
		auto iter = freq.begin() ;
		int maxfreq = 0 ;

		for( ; iter != freq.end() ; iter++ )
		{
			if( iter -> second > maxfreq )
				maxfreq = iter -> second ;
		}

		int steps = maxfreq * k ;
		cout << steps << "\n" ;
	}

}


// Zero Remainder Array
// https://codeforces.com/contest/1374/problem/D
// Aman Kumar

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ff first
#define ss second
#define MOD 1000000007

void func() ;

int main()
{
	ios_base::sync_with_stdio( 0 ) ;
	cin.tie(0) ;

	int t ;
	cin >> t ;

	while( t-- )
	{
	    func() ;
	}
	return 0 ;
}

void func()
{
	int n, k ;
	cin >> n >> k ;

	vector<int> a(n) ;

	for( int i = 0 ; i < n ; i++ )
		cin >> a[i] ;

	map<int,int> freq ;
	int maxfreq = 0 ;
	ll maxdiff = 0 ;

	for( int i = 0 ; i < n ; i++ )
	{
		if( a[i] % k != 0 )
		{
			int diff = k - (a[i] % k ) ;

			auto iter = freq.find( diff ) ;

			if( iter == freq.end() )
				freq[diff] = 1 ;
			else
				freq[diff]++ ;

			// Get max freq
			if( freq[diff] > maxfreq )
			{
				maxfreq = freq[diff] ;
				maxdiff = diff ;
			}
		}
	}

	ll steps = 0 ;

	auto iter = freq.begin() ;

	for( ; iter != freq.end() ; iter++ )
	{
		if( iter -> second == maxfreq )
			steps = k * 1ll * (iter->second -1) + (iter->first +1) ;
	}

	cout << steps << "\n" ;
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		freq[rem]++;
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first==0) continue;
		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
		if(rem==0) continue;
		freq[rem]++;
		if(mx<freq[rem])
		{
			mx=freq[rem];
			at=rem;
		}
		else if(mx==freq[rem])
		{
			at=max(at,rem);
		}
	}
	if(mx==0)
	cout<<0<<endl;
	ll ans=0;
	ans=max(k*(mx-1),0ull) + at +1;
//	for(auto x:freq)
//	{
//		if(x.first!=0)
//		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define ps(x,y)         fixed<<setprecision(y)<<x
#define cases(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

// Some contants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);

void solve()
{
	ll len,k;
	cin>>len>>k;
	ll max=0;
	ll at=-1;
	unordered_map<ll,ll> freq;
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
		if(temp%k!=0 && rem!=0)
		{
			freq[rem]++;
			if(max < freq[rem])
			{
				max=freq[rem];
				at = rem;
			}
		}
	}
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = k*max - (k-at-1);
	cout<<ans<<endl;

}

int main()
{
	cases(t)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define ps(x,y)         fixed<<setprecision(y)<<x
#define cases(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

// Some contants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);

void solve()
{
	ll len,k;
	cin>>len>>k;
	ll mx=0;
	ll at=-1;
	unordered_map<ll,ll> freq;
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
		cout<<rem<<" ";
		if(temp%k!=0 && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
	cout<<endl;
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = max(k*(mx-1),0ll) + at+1;
	cout<<ans<<endl;

}

int main()
{
	cases(t)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp)%k;
		if(rem==0) continue;
		freq[rem]++;
		if(mx<freq[rem])
		{
			mx=freq[rem];
			at=rem;
		}
		else if(mx==freq[rem])
		{
			at=max(at,rem);
		}
	}
	if(mx==0)
	{
	cout<<0<<endl;
	return;
	}
	ll ans=0;
	ans=max(k*(mx-1),0ull) + at +1;
//	for(auto x:freq)
//	{
//		if(x.first!=0)
//		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp)%k;
		if(rem==0 || rem==k) continue;
		freq[rem]++;
		if(mx<freq[rem])
		{
			mx=freq[rem];
			at=rem;
		}
		else if(mx==freq[rem])
		{
			at=max(at,rem);
		}
	}
	if(mx==0)
	{
	cout<<0<<endl;
	return;
	}
	ll ans=0;
	ans=max(k*(mx-1),0ull) + at +1;
//	for(auto x:freq)
//	{
//		if(x.first!=0)
//		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		if( rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
	ll ans=0;
	if(at!=-1)
		ans = max(ans, k*(mx-1) + at+1) ;
//	for(auto x:freq)
//	{
//		ans=max(ans, k*(x.second-1),0ull + x.first+1));
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
	//	cout<<rem<<" ";
		if(rem!=k && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
//	cout<<endl;
	if(at==-1){
	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans =0;
	for(auto x:freq)
	{
		ans=max(ans,max(k*(x.second-1),0ull) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		freq[rem]++;
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first==0) continue;
		ans=max(ans, k*(x.second-1ll) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		freq[rem]++;
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first!=0)
		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		if( rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first==0) continue;
		ans=max(ans, k*(x.second-1) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		if( rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
	ll ans=0;
	if(at!=-1)
		ans = max(ans, k*(mx-1) + at+1) ;
	for(auto x:freq)
	{
		ans=max(ans, k*(x.second-1) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
		if(rem==0) continue;
		freq[rem]++;
		if(mx<freq[rem])
		{
			mx=freq[rem];
			at=rem;
		}
		else if(mx==freq[rem])
		{
			at=max(at,rem);
		}
	}
	if(mx==0)
	{
	cout<<0<<endl;
	return;
	}
	ll ans=0;
	ans=max(k*(mx-1),0ull) + at +1;
//	for(auto x:freq)
//	{
//		if(x.first!=0)
//		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define ps(x,y)         fixed<<setprecision(y)<<x
#define cases(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

// Some contants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);

void solve()
{
	ll len,k;
	cin>>len>>k;
	ll mx=0;
	ll at=-1;
	unordered_map<ll,ll> freq;
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
	//	cout<<rem<<" ";
		if(rem!=k && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
//	cout<<endl;
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = max(k*(mx-1),0ull) + at+1;
	cout<<ans<<endl;

}

int main()
{
	cases(t)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
//		if(rem!=k && rem!=0)
//		{
//			freq[rem]++;
//			if(mx < freq[rem])
//			{
//				mx=freq[rem];
//				at = rem;
//			}
//		}
		freq[rem]++;
	}
//	cout<<endl;
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
//	if(freq[0]==n)
//	{
//		cout<<0<<endl;
//		return;
//	}
	ll ans =0;
	for(auto x:freq)
	{
		if(x.first!=0)
		ans=max(ans,(max(k*(x.second-1),0ull) + x.first+1));
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		freq[rem]++;
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first!=0)
		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
	//	cout<<rem<<" ";
		if(rem!=k && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
//	cout<<endl;
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = max(k*(mx-1),0ull) + at+1;
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define ps(x,y)         fixed<<setprecision(y)<<x
#define cases(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

// Some contants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);

void solve()
{
	ll len,k;
	cin>>len>>k;
	ll max=0;
	ll at=-1;
	unordered_map<ll,ll> freq;
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
		if(temp%k!=0)
		{
			freq[rem]++;
			if(max < freq[rem])
			{
				max=freq[rem];
				at = rem;
			}
		}
	}
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = k*max - (k-at-1);
	cout<<ans<<endl;

}

int main()
{
	cases(t)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp)%k;
		if(rem==0 || rem==k) continue;
		freq[rem]++;
		if(mx<freq[rem])
		{
			mx=freq[rem];
			at=rem;
		}
		else if(mx==freq[rem])
		{
			at=max(at,rem);
		}
	}
	if(mx==0)
	{
	cout<<0<<endl;
	return;
	}
	ll ans=0;
	ans=max(k*(mx-1),0ull) + at +1;
//	for(auto x:freq)
//	{
//		if(x.first!=0)
//		ans=max(ans, max(k*(x.second-1ll),0ull) + x.first+1);
//	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define ps(x,y)         fixed<<setprecision(y)<<x
#define cases(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

// Some contants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);

void solve()
{
	ll len,k;
	cin>>len>>k;
	ll mx=0;
	ll at=-1;
	int freq[k]={0};
	for(int i=0;i<len;i++)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
	//	cout<<rem<<" ";
		if(rem!=k && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
//	cout<<endl;
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = max(k*(mx-1),0ll) + at+1;
	cout<<ans<<endl;

}

int main()
{
	cases(t)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	int mx=0;
	ll at=-1;
	map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- ((temp-1)%k+1);
	//	cout<<rem<<" ";
//		if(rem!=k && rem!=0)
//		{
//			freq[rem]++;
//			if(mx < freq[rem])
//			{
//				mx=freq[rem];
//				at = rem;
//			}
//		}
		freq[rem]++;
	}
//	cout<<endl;
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans =0;
	for(auto x:freq)
	{
		ans=max(ans,(max(k*(x.second-1),0ull) + x.first+1));
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- temp%k;
	//	cout<<rem<<" ";
		if(rem!=k && rem!=0)
		{
			freq[rem]++;
			if(mx < freq[rem])
			{
				mx=freq[rem];
				at = rem;
			}
		}
	}
//	cout<<endl;
	if(at==-1){

	cout<<0<<endl;
	return;
}
//	cout<<"max freq  : "<<max<<" extra to remove : "<<at<<endl;
	ll ans = max(k*(mx-1),0ull) + at+1;
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

static int x = []() {ios::sync_with_stdio(false); cin.tie(0); return 0; } ();

// Some typedef's
//typedef long long ll;
typedef unsigned long long ll;
void solve()
{
	ll len,k;
	cin>>len>>k;
	ll n=len;
	int mx=0;
	ll at=-1;
	unordered_map<ll,int> freq;
	while(len--)
	{
		ll temp;
		cin>>temp;
		ll rem = k- (temp-1)%k-1;
	//	cout<<rem<<" ";
		freq[rem]++;
	}
	ll ans=0;
	for(auto x:freq)
	{
		if(x.first==0) continue;
		ans=max(ans, k*(x.second-1) + x.first+1);
	}
	cout<<ans<<endl;

}

int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	w(t)
	{
		int n,k;
		cin>>n>>k;
		int a[n];
		map<int,int> yo;
		for(int i=1;i<k;i++)
			yo.insert(mp(i,0));

		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			if(a[i]%k!=0)
				yo[a[i]%k]++;
		}
		int min=0;
		int count=0;
		for(int i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			int t=k-min;
			for(int i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;
		int a[n];

		count=0;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]=a[i]%k;

		}
		sort(a,a+n);
		t=1;
		for(i=0;i<n;i++)
		{
			if(a[i]!=0)
				break;
		}
		int s=i;
		bool p=true;
		for(i=s+1;i<n;i++)
		{
			if(a[i]==a[i-1])
				t++;
			else
			{
				p=false;
				if(t>count)
				{
					count=t;
					min=a[i-1];
				}
				t=1;
			}
		}
		if(p)
		{
			min=a[n-1];
			count=i-s;

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else if(count==1)
		{
			cout<<n<<endl;
		}
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;
		int a[n];

		count=0;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]=a[i]%k;

		}
		sort(a,a+n);
		t=1;
		for(i=0;i<n;i++)
		{
			if(a[i]!=0)
				break;
		}
		int s=i;
		bool p=true;
		for(i=s+1;i<n;i++)
		{
			if(a[i]==a[i-1])
				t++;
			else
			{
				p=false;
				if(t>count)
				{
					count=t;
					min=a[i-1];
				}
				t=1;
			}
		}
		if(p)
		{
			min=a[n-1];
			count=i-s;

		}
		if(min==0)
			cout<<0<<endl;
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<iostream>
using namespace std;

// #define inf  1e18
// #define int  long long
// #define float double
#define endl  "\n"
// #define w(t)  int t;cin>>t;while(t--)
// #define str  to_string
// #define vci  vector<int>
// #define vcs  vector<string>
// #define mp   make_pair
// #define pb   push_back
// #define pii   pair<int,int>
// #define pis   pair<int,string>
// #define fastio() ios::sync_with_stdio(0);cin.tie(0)
// #define mod   1000000007
// random_device rd;
// mt19937 rand_gen(rd());
// #define setbits(x)     __builtin_popcountll(x)
// #define trailzero(x)   __builtin_ctzll(x)
// #define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
// #define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int main()
{

	// fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;

		int yo[k]={0};

		for(i=0;i<n;i++)
		{
			cin>>t;

			yo[t%k]++;
		}

		for(i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;
		int a[n];

		count=0;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]=a[i]%k;

		}
		sort(a,a+n);
		t=1;
		for(i=0;i<n;i++)
		{
			if(a[i]!=0)
				break;
		}
		int s=i;
		bool p=true;
		for(i=s+1;i<n;i++)
		{
			if(a[i]==a[i-1])
				t++;
			else
			{
				p=false;
				if(t>count)
				{
					count=t;
					min=a[i-1];
				}
				t=1;
			}
		}
		if(p)
		{
			min=a[n-1];
			count=i-s;

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else if(count==1)
		{
			cout<<k-min+1<<endl;
		}
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
// #define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int main()
{

	fastio();
	io();
	w(t)
	{
		int n,k,i;
		cin>>n>>k;
		int a[n];
		int yo[k]={0};

		for(i=0;i<n;i++)
		{
			cin>>a[i];

			yo[a[i]%k]++;
		}
		int min=0;
		int count=0;
		for(i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			int t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;
		int a[n];

		count=0;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]=a[i]%k;

		}
		sort(a,a+n);
		t=1;
		for(i=0;i<n;i++)
		{
			if(a[i]!=0)
				break;
		}
		int s=i;
		min=a[i];
		bool p=true;
		for(i=s+1;i<n;i++)
		{
			if(a[i]==a[i-1])
				t++;
			else
			{
				p=false;
				if(t>count)
				{
					count=t;
					min=a[i-1];
				}
				t=1;
			}
		}
		if(t>count)
		{
			count=t;
			min=a[n-1];
		}
		if(p)
		{
			min=a[n-1];
			count=i-s;

		}
		if(min==0)
			cout<<0<<endl;
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	w(t)
	{
		int n,k;
		cin>>n>>k;
		int a[n];
		int yo[k]={0};

		for(int i=0;i<n;i++)
		{
			cin>>a[i];

			yo[a[i]%k]++;
		}
		int min=0;
		int count=0;
		for(int i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			int t=k-min;
			for(int i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int32_t main()
{

	fastio();
	io();
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,i,t,min=0,count=0;
		cin>>n>>k;
		map<int,int> yo;

		for(i=0;i<n;i++)
		{
			cin>>t;
			int p=t%k;
			if(yo.find(p)==yo.end())
				yo.insert(mp(p,0));
			yo[p]++;

		}
		min=0;
		count=0;
		for(i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;

#define inf  1e18
// #define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string>
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);

		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}

int main()
{

	fastio();
	io();
	w(t)
	{
		int n,k,i,t;
		cin>>n>>k;

		int yo[k]={0};

		for(i=0;i<n;i++)
		{
			cin>>t;

			yo[t%k]++;
		}
		int min=0;
		int count=0;
		for(i=1;i<k;i++)
		{
			if(yo[i]>count)
			{
				min=i;
				count=yo[i];

			}

		}
		if(min==0)
		{
			cout<<0<<endl;
		}
		else
		{
			t=k-min;
			for(i=1;i<count;i++)
				t+=k;
			cout<<t+1<<endl;
		}

	}

}