#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

 int n;
 cin>>n;
 int a[n];
 ll as=0;
 ll cum1[n+1]={};
 for(int i=0;i<n;i++){
    cin>>a[i];
    cum1[i+1]=a[i];
    as+=a[i];
 }
 for(int i=2;i<=n;i++)
    cum1[i]+=cum1[i-1];
 int m;
 cin>>m;
 int b[m];
 ll bs=0;
 ll cum2[m+1]={};
 for(int i=0;i<m;i++){
    cin>>b[i];
    cum2[i+1]=b[i];
    bs+=b[i];
 }
  int ans=0;
  if(binary_search(cum1,cum1+n+1,cum2[1]))
    ans++;
 for(int i=2;i<=m;i++)
   {
       cum2[i]+=cum2[i-1];
       if(binary_search(cum1+1,cum1+n+1,cum2[i]))
                    ans++;
   }
    if(bs!=as)
        cout<<-1;
    else
          cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

 int n;
 cin>>n;
 int a[n];
 ll as=0;
 int cum1[n+1]={};
 for(int i=0;i<n;i++){
    cin>>a[i];
    cum1[i+1]=a[i];
    as+=a[i];
 }
 for(int i=2;i<=n;i++)
    cum1[i]+=cum1[i-1];
 int m;
 cin>>m;
 int b[m];
 ll bs=0;
 int cum2[m+1]={};
 for(int i=0;i<m;i++){
    cin>>b[i];
    cum2[i+1]=b[i];
    bs+=b[i];
 }
  int ans=0;
  if(binary_search(cum1,cum1+n+1,cum2[1]))
    ans++;
 for(int i=2;i<=m;i++)
   {
       cum2[i]+=cum2[i-1];
       if(binary_search(cum1+1,cum1+n+1,cum2[i]))
                    ans++;
   }
    if(bs!=as)
        cout<<-1;
    else
          cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
    cin.tie(0);
 int n;
 cin>>n;
 int a[n];
 ll as=0;
 ll cum1[n+1]={};
 for(int i=0;i<n;i++){
    cin>>a[i];
    cum1[i+1]=a[i];
    as+=a[i];
 }
 for(int i=2;i<=n;i++)
    cum1[i]+=cum1[i-1];
 int m;
 cin>>m;
 int b[m];
 ll bs=0;
 ll cum2[m+1]={};
 for(int i=0;i<m;i++){
    cin>>b[i];
    cum2[i+1]=b[i];
    bs+=b[i];
 }
  int ans=0;
  if(binary_search(cum1,cum1+n+1,cum2[1]))
    ans++;
 for(int i=2;i<=m;i++)
   {
       cum2[i]+=cum2[i-1];
       if(binary_search(cum1+1,cum1+n+1,cum2[i]))
                    ans++;
   }
    if(bs!=as)
        cout<<-1;
    else
          cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,m,i,j,x;
    vector<long long> A,B;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> x;  A.push_back(x);
    }
    cin >> m;
    for(i=0;i<m;i++){
        cin >> x; B.push_back(x);
    }
    long long sum1=0,sum2=0,cpt=0;
    i=0;j=0;
    while(i<n && j<m){
        if (sum1==sum2) { cpt++; sum1+=A[i]; sum2+=B[j]; i++; j++; }
        else {
            if (sum1<sum2) { sum1+=A[i]; i++; }
            else { sum2+=B[j]; j++;}
        }
    }
    if (sum1!=sum2) cout << -1;
    else cout << cpt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n,m,i,j,x;
    long long sum1=0,sum2=0,cpt=0;
    vector<long long> A,B;
    cin >> n;
    for(i=0;i<n;i++){
        scanf("%lld",&x);  A.push_back(x);
        sum1+=x;
    }
    cin >> m;
    for(i=0;i<m;i++){
        scanf("%lld",&x); B.push_back(x);
        sum2+=x;
    }
    if (sum1!=sum2) return cout << -1,0;
    i=0;j=0;
    while(i<n && j<m){
        if (sum1==sum2) { cpt++; sum1+=A[i]; sum2+=B[j]; i++; j++; }
        else {
            if (sum1<sum2) { sum1+=A[i]; i++; }
            else { sum2+=B[j]; j++;}
        }
    }
    cout << cpt;
    return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
    int i,j,n,k;
    cin >> n >> k;
    if(k==1){
        cin >> j;
        n--;
        while(n--){
            cin >> i;
            if(i!=j){
                break;
            }
        }
        if(n==0)
            cout << 1<<endl;
         else
            cout << -1 <<endl;

        }else{
           int cnt = 0;
           cin >> j;
           n--;
           while(n--){
            cin >> i;
            if(abs(i-j)>0){
                cnt++;
            }
            j=i;
           }
           cout << cnt/(k-1) <<endl;

        }

}

return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
        int n,k,i,j;
        cin >> n >> k;
        if(k==1){
            vector<int>arr(n);
            for(i=0;i<n;++i)
                cin >> arr[i];
            for(i=1;i<n;++i){
                if(arr[i]!=arr[i-1])
                    break;
            }
            if(i==n)
                cout << 1 <<endl;
            else
                cout <<-1 <<endl;

        }else{
        int cnt =0 ;
        vector<int>arr(n);
        for(i=0;i<n;++i)
            cin >>arr[i];
        for(i=1;i<n;++i)
            if(arr[i]-arr[i-1]!=0)
               cnt++;
        cout << ceil(cnt*1.0/(k-1)*1.0)<<endl;        }

}

return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
        int n,k,i,j;
        cin >> n >> k;
        if(k==1){
            vector<int>arr(n);
            for(i=0;i<n;++i)
                cin >> arr[i];
            for(i=1;i<n;++i){
                if(arr[i]!=arr[i-1])
                    break;
            }
            if(i==n)
                cout << 1 <<endl;
            else
                cout <<-1 <<endl;

        }else{
        int cnt =0 ;
        vector<int>arr(n);
        for(i=0;i<n;++i)
            cin >>arr[i];
        for(i=1;i<n;++i)
            if(arr[i]-arr[i-1]!=0)
               cnt++;
        int ans = ceil(cnt*1.0/(k-1)*1.0);
                cout << max(1,ans)<<endl;
                }

}

return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
    int i,j,n,k;
    cin >> n >> k;
    if(k==1){
        cin >> j;
        n--;
        while(n--){
            cin >> i;
            if(i!=j){
                cout << -1 <<endl;
                break;
            }
        }
        if(n==0)
            cout << 1<<endl;

        }else{
           int cnt = 0;
           cin >> j;
           n--;
           while(n--){
            cin >> i;
            if(abs(i-j)>0){
                cnt++;
            }
            j=i;
           }
           cout << cnt/(k-1) <<endl;

        }

}

return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
        int n,k,i,j;
        cin >> n >> k;
        if(k==1){
            vector<int>arr(n);
            for(i=0;i<n;++i)
                cin >> arr[i];
            for(i=1;i<n;++i){
                if(arr[i]!=arr[i-1])
                    break;
            }
            if(i==n)
                cout << 1 <<endl;
            else
                cout <<-1 <<endl;

        }else{
        int cnt =0 ;
        vector<int>arr(n);
        for(i=0;i<n;++i)
            cin >>arr[i];
        for(i=1;i<n;++i)
            if(arr[i]-arr[i-1]!=0)
               cnt++;
        cout << max(1,ceil(cnt*1.0/(k-1)*1.0))<<endl;        }

}

return 0;
}


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

int main(){
int t;
cin >>t;
while(t--){
        int n,k,i,j;
        cin >> n >> k;
        if(k==1){
            vector<int>arr(n);
            for(i=0;i<n;++i)
                cin >> arr[i];
            for(i=1;i<n;++i){
                if(arr[i]!=arr[i-1])
                    break;
            }
            if(i==n)
                cout << 1 <<endl;
            else
                cout <<-1 <<endl;

        }else{
        int cnt =0 ;
        vector<int>arr(n);
        for(i=0;i<n;++i)
            cin >>arr[i];
        for(i=1;i<n;++i)
            if(arr[i]-arr[i-1]!=0)
               cnt++;
        cout << cnt/(k-1)<<endl;

        }

}

return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                  else cout<<(int)ceil((double)d/(double)m)<<endl;

   }
 return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                   else if(d==1&&m==1) cout<<1<<endl;
                  else
                             cout<<max(0,(int)ceil((double)(d-m)/(double)(m-1)))+1<<endl;

    }
 return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                  else cout<<(int)ceil((double)(d-m)/(double)m)+1<<endl;

   }
 return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                   else if(d==1&&m==1) cout<<1<<endl;
                  else
                             cout<<ceil((double)(d-m)/(double)(m-1))+1<<endl;

    }
 return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                  else{
                               while(d>m) {
                                     d-=m;
                                     ans++;
                               }
                   cout<<ans+1<<endl;
                  }

   }
 return 0;
}


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

int main(){
   int t;
   cin>>t;
   while(t--) {
          int n, m;
          cin>>n>>m;
            set<int>s;
             for(int i=1;i<=n;i++) {
                    int a;
                    cin>>a;
                    s.insert(a);

            }
                  int d=s.size();
                  int ans=0;
                  if(m==1&&d>1)  cout<<-1<<endl;
                   else if(d==1&&m==1) cout<<1<<endl;
                  else
                             cout<<max(0,(int)ceil((double)(d-m+1)/(double)(m-1)))+1<<endl;

    }
 return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

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

    set<int> present;
    for(int i = 0;i<n;i++)
    {
        present.insert(a[i]);
    }
    x = present.size();
    //cout<<x<<" ";

    int ans=0;
    for(int i = k;i>=0;i--)
    {
        if(x<=0)
        {
            cout<<ans;
            return;
        }
        x-=i;
        ans++;
    }

    cout<<-1;
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

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

    set<int> present;
    for(int i = 0;i<n;i++)
    {
        present.insert(a[i]);
    }
    x = present.size();
    //cout<<x<<" ";

    if(k==1)
    {
        if(x>1)
            cout<<-1;
        else
            cout<<1;
        return;
    }

    int ans = ceil(x/double(k));

    cout<<ans;
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

    for(int i =0;i<n;i++)
        cin>>a[i];
    int x = 0;
    for(int i = 1;i<n;i++)
    {
        if(a[i]==a[i-1])
        {
            while(i<n and a[i]==a[i-1])
                i++;
            i--;
        }
        x++;
    }

    int ans =1;
    for(int i = k;k>0;k--)
    {
        if(x<0)
        {
            cout<<ans;
            return;
        }
        x-=i;
        ans++;
    }

    cout<<-1;
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

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

    set<int> present;
    for(int i = 0;i<n;i++)
    {
        present.insert(a[i]);
    }
    x = present.size();
    //cout<<x<<" ";

    if(k==1)
    {
        if(x>1)
            cout<<-1;
        else
            cout<<1;
        return;
    }

    int ans = ceil((x-1)/double(k-1));

    cout<<ans;
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

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

    set<int> present;
    for(int i = 0;i<n;i++)
    {
        present.insert(a[i]);
    }
    x = present.size();
    //cout<<x<<" ";

    if(k==1)
    {
        if(x>1)
            cout<<-1;
        else
            cout<<1;
        return;
    }

    int ans = ceil((x-1)/double(k-1));

    cout<<ans?ans:1;
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


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

#define sync {ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
#define int long long int
#define mod 1000000007

int n,k;

void solve()
{
    cin>>n>>k;
    int a[n];

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

    set<int> present;
    for(int i = 0;i<n;i++)
    {
        present.insert(a[i]);
    }
    x = present.size();
    //cout<<x<<" ";

    if(k==1)
    {
        if(x>1)
            cout<<-1;
        else
            cout<<1;
        return;
    }

    int ans = ceil((x-1)/double(k-1));

    cout<<(ans?ans:1);
}

int32_t main()
{
    sync;
    int t = 1;
    cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 31;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("p4.txt", "w", stdout);
#endif
}

void solve()
{
  int n, k; cin >> n >> k;
  int a[n];
  set<int>s, s1, s2;
  FOR(i, 0, n)cin >> a[i], s.insert(a[i]);
  if (s.size() <= k)
  {
    cout << "1\n";
    return;
  }
  int x, flag = 0, j = 0, i = 0;
  for (i = 0; i < n; i++)
  {
    if (k >= s1.size())
    {
      s1.insert(a[i]);
      if (s1.size() > k)
      {
        flag = 1;
        j = i;
        break;
      }
      x = a[i];
      s2.insert(0);
    }
  }
  for (int j = i; j < n; j++)
  {
    if (k >= s2.size())
    {
      s2.insert(a[j] - x);
      if (s2.size() > k)
      {
        flag = 2;
        break;
      }
      s2.insert(a[j] - x);
    }
  }
  if (flag == 1 || flag == 0)cout << "2\n";
  else if (flag == 2)cout << "-1\n";
}
int32_t main()
{
  c_p_c();
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 31;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("p4.txt", "w", stdout);
#endif
}

void solve()
{
  int n, k; cin >> n >> k;
  int a[n];
  set<int>s, s1, s2;
  FOR(i, 0, n)cin >> a[i], s.insert(a[i]);
  if (s.size() <= k)
  {
    cout << "1\n";
    return;
  }
  else if (s.size() <= 2 * k - 1)
  {
    cout << '2' << '\n';
  }
  else cout << "-1\n";

}
int32_t main()
{
  c_p_c();
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("p4.txt", "w", stdout);
#endif
}

void solve()
{
  int n, k; cin >> n >> k;
  int a[n];
  set<int>s, s1, s2;
  FOR(i, 0, n)cin >> a[i], s.insert(a[i]);
  if (s.size() <= k)
  {
    cout << "1\n";
    return;
  }
  if (k == 1 and s.size() > k)
  {
    cout << "-1\n";
    return;
  }
  int x, cnt = 1;
  for (int i = 0; i < n; i++)
  {
    s1.insert(a[i]);
    if (s1.size() > k)
    {
      cnt++;
      s1.clear();
      s1.insert(0);
      s1.insert(a[i]);
    }
  }
  cout << cnt << '\n';

}
int32_t main()
{
  c_p_c();
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 31;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("p4.txt", "w", stdout);
#endif
}

void solve()
{
  int n, k; cin >> n >> k;
  int a[n];
  set<int>s, s1, s2;
  FOR(i, 0, n)cin >> a[i], s.insert(a[i]);
  if (s.size() <= k)
  {
    cout << "1\n";
    return;
  }
  if (k == 1 and s.size() > k)
  {
    cout << "-1\n";
    return;
  }
  int x, cnt = 1;
  for (int i = 0; i < n; i++)
  {
    s1.insert(a[i]);
    if (s1.size() > k)
    {
      cnt++;
      s1.clear();
      s1.insert(0);
      s1.insert(a[i]);
    }
  }
  cout << cnt << '\n';

}
int32_t main()
{
  c_p_c();
  w(t)
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define sz                size();
#define p_sieve           1000007
const int                 maxn = 1e3 + 5;
#define mod               1000000009;
const int                 p = 31;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("p4.txt", "w", stdout);
#endif
}

void solve()
{
  int n, k; cin >> n >> k;
  int a[n];
  set<int>s, s1, s2;
  FOR(i, 0, n)cin >> a[i], s.insert(a[i]);
  if (s.size() <= k)
  {
    cout << "1\n";
    return;
  }
  int x, flag = 0, j = 0, i = 0;
  for (i = 0; i < n; i++)
  {
    if (k >= s1.size())
    {
      s1.insert(a[i]);
      if (s1.size() > k)
      {
        flag = 1;
        j = i;
        break;
      }
      x = a[i];
      s2.insert(0);
    }
  }
  if (flag == 1)
  { for (int j = i; j < n; j++)
    {
      if (k >= s2.size())
      {
        s2.insert(a[j] - x);
        if (s2.size() > k)
        {
          flag = 2;
          break;
        }
        s2.insert(a[j] - x);
      }
    }
  }
  if (flag == 1 || flag == 0)cout << "2\n";
  else if (flag == 2)cout << "-1\n";
}
int32_t main()
{
  c_p_c();
  w(t)
  solve();
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>=k*k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=(cnt+k)/k;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

   // if(cnt<k)

    cout<<cnt/k<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;
    if(z>k)
    {cout<<"-1"<<endl;continue;}
    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=log2(cnt);

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(cnt==k) {cout<<"1"<<endl;continue;}

    int z=cnt-k;

    int y=cnt/k;
    if(cnt%k) y++;
    z=min(z,y);

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    vector<int> a;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(s.count(x)) continue;
        a.push_back(x);
        s.insert(x);
    }

    if(k==1 && a.size()>1) {cout<<"-1"<<endl;continue;}
    if(a.size()<k)
    {cout<<"1"<<endl; continue;}

    int F=a[k-1];
    set<int>S;

    for(int i=k;i<a.size();i++)
    {
        S.insert(a[i]-F);
    }
    int ans=S.size();
    k--;
    int z=ans/k;
    if(ans%k) z++;
    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(cnt==k) {cout<<"1"<<endl;continue;}

    int z=cnt-k;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    vector<int> a;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(s.count(x)) continue;
        a.push_back(x);
        s.insert(x);
    }

    if(k==1 && a.size()>1) {cout<<"-1"<<endl;continue;}
    if(a.size()<k)
    {cout<<"1"<<endl; continue;}

    int ans=a.size()-k+1;
    cout<<ans<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>k*k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    z=min(2,z);

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

   // if(cnt<k)

    if(max(1,cnt-k)==1)
    cout<<"1"<<endl;
    else
    cout<<"2"<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;
    if(z>=k)
    {cout<<"-1"<<endl;continue;}
    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(cnt>k*k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;

    if(cnt%k) z++;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(cnt,k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;

    if(cnt%k) z++;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{

    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(1,cnt-k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt*cnt>k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;

    if(cnt%k) z++;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>=2*k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

   // if(cnt<k)
    int z=cnt/k;
    if(cnt%k) z++;
    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(cnt==k) {cout<<"1"<<endl;continue;}

    int z=(cnt+k)/k;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(1,cnt-k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(0,cnt-k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(cnt==k) {cout<<"1"<<endl;continue;}

    int z=cnt-k;

    int y=cnt/k;
    if(cnt%k) y++;
    z=min(z,y);

    z=min(n,z);

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=log(cnt)/log(k);

//    if(cnt%k) z++;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=log(cnt)/log(k);

    if(log(cnt) % log (k) ) z++;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(0,cnt-k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(max(1,cnt)==1)
    cout<<"1"<<endl;
    else
    cout<<"2"<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;

    if(cnt%k) z+=(cnt%k);

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;

    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    cout<<max(1,cnt-k)<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }
    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>k*k) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    if(cnt==k) {cout<<"1"<<endl;continue;}

    int z=cnt-k;

    z=min(n,z);

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;

    cout<<z<<endl;

}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    int cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(!m[x]) cnt++;
        m[x]++;
    }

    if(k==1 && cnt>1) {cout<<"-1"<<endl;continue;}

    int z=cnt/k;
    if(cnt%k) z++;

    z=min(2,z);

    cout<<z<<endl;
}
return 0;
}


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

signed main()
{
int tc,x;cin>>tc;
while(tc--)
{
    int n,k;
    cin>>n>>k;
    vector<int> a;
    set<int>s;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(s.count(x)) continue;
        a.push_back(x);
        s.insert(x);
    }

    if(k==1 && a.size()>1) {cout<<"-1"<<endl;continue;}
    if(a.size()<k)
    {cout<<"1"<<endl; continue;}

    int F=a[k-1];
    set<int>S;

    for(int i=k;i<a.size();i++)
    {
        S.insert(a[i]-F);
    }
    int ans=S.size();
    k--;
    int z=ans/k;
    if(ans%k) z++;
    cout<<z+1<<endl;

}
return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n,k;
        vector<int> a(n);
        set<int> x;
        rep(i,0,n)
            cin>>a[i],x.insert(a[i]);
   //     see(_sz(x));
        if(_sz(x)==k){
            cout<<1<<nl;
            continue;
        }
        if(_sz(x)<2*k){
            cout<<2<<nl;
        }
        else cout<<-1<<nl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n>>k;
        map<int,int> mp;
        rep(i,0,n){
            int gg;
            cin>>gg;
            mp[gg]++;
        }
        if(_sz(mp)==k){
            cout<<1<<nl;
            continue;
        }
        if(_sz(mp)<2*k){
            cout<<(_sz(mp)+k-1)/k<<nl;
        }
        else cout<<-1<<nl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n>>k;
        set<int> st;
        rep(i,0,n){
            int x;
            cin>>x;
            st.insert(x);
        }
        if(k==1){
            if(_sz(st)==1)
                cout<<1<<nl;
            else cout<<-1<<nl;
            continue;
        }
        if(k>=_sz(st)){
            cout<<1<<nl;
            continue;
        }
        cout<<(_sz(st)-1+k-2)/(k-1)<<nl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n>>k;
        map<int,int> mp;
        rep(i,0,n){
            int gg;
            cin>>gg;
            mp[gg]++;
        }
        if(_sz(mp)==k){
            cout<<1<<nl;
            continue;
        }
        if(k==1){
            cout<<-1<<nl;
            continue;
        }
        int k1=_sz(mp)-k;
        int as=k1/(k-1);
        if(k1%(k-1))
            as++;
        as++;
        cout<<as<<nl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n>>k;
        map<int,int> mp;
        rep(i,0,n){
            int gg;
            cin>>gg;
            mp[gg]++;
        }
        if(_sz(mp)==k){
            cout<<1<<nl;
            continue;
        }
        if(_sz(mp)<2*k){
            cout<<2<<nl;
        }
        else cout<<-1<<nl;
    }
    return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    tc{
        int n,k;
        cin>>n>>k;
        map<int,int> mp;
        rep(i,0,n){
            int gg;
            cin>>gg;
            mp[gg]++;
        }
        int k1=_sz(mp)-k;
        int l=_sz(mp);
        if(k==1){
            if(l==1)
                cout<<1<<nl;
            else cout<<-1<<nl;
            continue;
        }
        else if(k>=l){
            cout<<1<<nl;
            continue;
        }
        int as=k1/(k-1);
        if(k1%(k-1))
            as++;
        as++;
        cout<<as<<nl;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[10005][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        for(ll i = 1; i < n; i++)
        {
            a[i] -= a[0];
        }
        a[0] = 0;
        for(ll i = 1; i <= 100; i++) v[i] = false;
        v[0] = true;
        memset(b, 0, sizeof(b));
        ll now = 0;
        ll now2 = 1;
        for(ll i = 0; i < n; i++)
        {
            if(v[a[i]]) continue;
            b[now][now2] = a[i];
            for(ll j = 100; j >= 0; j--)
            {
                if(v[j] && j + b[now][now2] - b[now][now2 - 1] <= 100) v[j + b[now][now2] - b[now][now2 - 1]] = true;
            }
            if(now2 >= k - 1) now++, now2 = 1;
            else now2++;
        }
        if(now2 == 1) printf("%lld\n", now);
        else printf("%lld\n", now + 1);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[105][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        ll now = 1;
        ll cnt = 0;
        for(ll i = 1; i < n; i++)
        {
            cnt++;
            if(cnt >= k) cnt = 1, now++;
            for(ll j = i + 1; j < n; j++) a[j] -= a[i];
            a[i] = 0;
        }
        printf("%lld\n", now);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[105][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        if(n == 1) printf("1\n");
        else printf("%lld\n", (n - 1 + k - 1 - 1) / (k - 1));
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[105][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        printf("%lld\n", (n - 1 + k - 1 - 1) / (k - 1));
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[10005][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        for(ll i = 1; i < n; i++)
        {
            a[i] -= a[0];
        }
        a[0] = 0;
        for(ll i = 1; i <= 100; i++) v[i] = false;
        v[0] = true;
        memset(b, 0, sizeof(b));
        ll now = 0;
        ll now2 = 1;
        for(ll i = 0; i < n; i++)
        {
            if(v[a[i]]) continue;
            b[now][now2] = a[i];
            for(ll j = 100; j >= 0; j--)
            {
                if(v[j] && j + b[now][now2] - b[now][now2 - 1] <= 100) v[j + b[now][now2] - b[now][now2 - 1]] = true;
            }
            if(now2 >= k - 1) now++, now2 = 1;
            else now2++;
        }
        if(now == 0) printf("1\n");
        else if(now2 == 1) printf("%lld\n", now);
        else printf("%lld\n", now + 1);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long ll;

ll T;
ll n, k;
ll a[105];
ll b[105][105];
bool v[105];

int main()
{
    scanf("%lld", &T);
    while(T--)
    {
        scanf("%lld%lld", &n, &k);
        for(ll i = 0; i < n; i++)
        {
            scanf("%lld", &a[i]);
        }
        n = unique(a, a + n) - a;
        if(k == 1)
        {
            if(n == 1)
            {
                printf("1\n");
                continue;
            }
            else
            {
                printf("-1\n");
                continue;
            }
        }
        ll now = 1;
        ll cnt = 0;
        for(ll i = 1; i < n; i++)
        {
            cnt++;
            if(cnt >= k + 1) cnt = 1, now++;
            for(ll j = i + 1; j < n; j++) a[j] -= a[i];
            a[i] = 0;
        }
        printf("%lld\n", now);
    }
    return 0;
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
        cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {   int ans = 101;
        while (ans * (k - 1) > m - 1)
            ans--;
        cout << ans << endl;
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
        cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {
        if (m <= k)
            cout << 1 << endl;
        else
        {
            int ans = m / k + 1;
            cout << ans << endl;
        }
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
        cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {   int ans = 101;
        while (ans * (k - 1) >= m - 1)
            ans--;
        if (ans == 0)
            ans++;
        cout << ans + 1 << endl;
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
    cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {
        int ans;
        if (m % k != 0)
        ans = m / k + 1;
        else
            ans = m / k;
        cout << ans << endl;
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    solve();
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
        cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {   int ans = 101;
        while (ans * (k - 1) >= m - 1)
            ans--;
        if (ans == -1)
            ans++;
        cout << ans + 1 << endl;
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define vi vector<int>
#define For(i, a, b) for(int i = (a); i < (b); ++i)
#define Rfor(i, b, a) for(int i = (b); i > (a); --i)
using namespace std;
struct triple
{
    int x, y, z;
};
void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    int m = 1;
    For (i, 0, n)
        cin >> v[i];
    For (i, 1, n)
    {
        if (v[i] != v[i - 1])
            m++;
    }
    if (k == 1 && m > 1)
        cout << -1 << endl;
    else if (k == 1 && m == 1)
        cout << 1 << endl;
    else
    {   int ans = 101;
        while (ans * (k - 1) >= m - 1)
            ans--;
        cout << ans + 1 << endl;
    }

}

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        set<int>p;\
        set<int>ns;
        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(!s.count(0))s.insert(0);
                    continue;
                }
                if(s.count(a[i]))a[i]=-1;
                else if(!s.count(a[i]))
                {
                    int z=0;

                    for(auto it=s.begin();it!=s.end();++it)
                    {
                        if(p.count(a[i]-*it)!=0 && ns.count(a[i]-*it)==0)
                        {
                            a[i]=-1;
                            z=1;
                            break;
                        }
                    }

                    if(z==1)continue;

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }

            }

            for(auto it=s.begin();it!= s.end();++it)
            {
                //cout<<*it<<" ";
                p.insert(*it);
            }

            int cnt=0;

            f(i,0,n)
            {

                if(a[i]==-1)cnt++;
            }
           // cout<<endl;

            if(cnt==n){cout<<ans<<endl;
            break;}

            ns.insert(*s.begin());

        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
        }
        else
        {
            set<int>s;
            f(i,0,n)s.insert(a[i]);
            int ans=s.size()/(k-1);
            if(s.size()%k)ans++;
            cout<<ans<<endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
        }
        else
        {
            set<int>s;
            f(i,0,n)s.insert(a[i]);
            s.erase(0);
            int ans=s.size()/(k-1);
            if(s.size()%k)ans++;
            cout<<ans<<endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(!s.count(0))s.insert(0);
                    continue;
                }
                if(s.count(a[i]))a[i]=-1;
                else if(!s.count(a[i]))
                {

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }

            }

            int cnt=0;

            f(i,0,n)
            {

                if(a[i]==-1)cnt++;
            }
           // cout<<endl;

            if(cnt==n){cout<<ans<<endl;
            break;}

        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        set<int>p;
        set<int>ns;
        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(s.count(0)==0)s.insert(0);
                    continue;
                }
                if(s.count(a[i])==0)
                {
                    int z=0;

                    for(auto it=s.begin();it!= s.end();++it)
                    {
                        if(p.count(a[i]-*it)!=0 && ns.count(a[i]-*it)==0)
                        {
                            a[i]=-1;
                            z=1;break;
                        }
                    }

                    if(z==1)continue;

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }
            }

            for(auto it=s.begin();it!= s.end();++it)
            {
                p.insert(*it);
            }

            int cnt=0;
            f(i,0,n)
            {
                if(a[i]==-1)cnt++;
                a[i]-=*s.begin();
            }

            if(cnt==n){cout<<ans<<endl;
            break;}

            ns.insert(*s.begin());

        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        set<int>p;
        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(!s.count(0))s.insert(0);
                    continue;
                }
                if(s.count(a[i]))a[i]=-1;
                else if(!s.count(a[i]))
                {
                    int z=0;

                    for(auto it=s.begin();it!=s.end();++it)
                    {
                        if(p.count(a[i]-*it)!=0)
                        {
                            a[i]=-1;
                            z=1;
                            break;
                        }
                    }

                    if(z==1)continue;

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }

            }

            for(auto it=s.begin();it!= s.end();++it)
            {
                //cout<<*it<<" ";
                p.insert(*it);
            }

            int cnt=0;

            f(i,0,n)
            {

                if(a[i]==-1)cnt++;
            }
           // cout<<endl;

            if(cnt==n){cout<<ans<<endl;
            break;}

        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
        }
        else
        {
            set<int>s;
            f(i,0,n)s.insert(a[i]);
            cout<<s.size()/(k-1)<<endl;
        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        set<int>p;
        set<int>ns;
        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(s.count(0)==0)s.insert(0);
                    continue;
                }
                if(s.count(a[i])==0)
                {
                    int z=0;

                    for(auto it=s.begin();it!= s.end();++it)
                    {
                        if(p.count(a[i]-*it)!=0 && ns.count(a[i]-*it)==0)
                        {
                            a[i]=-1;
                            z=1;break;
                        }
                    }

                    if(z==1)continue;

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }
            }

            for(auto it=s.begin();it!= s.end();++it)
            {
                p.insert(*it);
            }

            int cnt=0;
            f(i,0,n)
            {
                if(a[i]==-1)cnt++;
            }

            if(cnt==n){cout<<ans<<endl;
            break;}

            ns.insert(*s.begin());

        }

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int>
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define mem(a,n) memset(a,n,sizeof a)
#define ln(a) a.length()
#define sz(a) (ll)a.size()
#define pi 3.14159265358979

const ll M=1e9+7;
const int P=31;
const int MaxM=200005;
/*__________________________________________________________________________________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

     #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int t;cin>>t;
    while(t--)
    {
        int n,k;cin>>n>>k;
        int a[n];f(i,0,n)cin>>a[i];

        if(k==1)
        {
            int z=0;
            int x=a[0];
            f(i,1,n)if(a[i]!=x){cout<<-1<<endl;z=1;break;}
            if(z==0)cout<<1<<endl;
            continue;
        }

        set<int>p;
        set<int>ns;
        int ans=0;
        while(1)
        {
            sort(a,a+n);
            ans++;
            set<int>s;
            f(i,0,n)
            {
                if(a[i]==-1)
                {
                    if(s.count(0)==0)s.insert(0);
                    continue;
                }
                if(s.count(a[i])==0)
                {
                    int z=0;

                    for(auto it=s.begin();it!= s.end();++it)
                    {
                        if(p.count(a[i]-*it)!=0 && ns.count(a[i]-*it)==0)
                        {
                            a[i]=-1;
                            z=1;break;
                        }
                    }

                    if(z==1)continue;

                    if(s.size()==k)break;
                    s.insert(a[i]);
                    a[i]=-1;
                }
            }

            for(auto it=s.begin();it!= s.end();++it)
            {
                p.insert(*it);
            }

            int cnt=0;
            f(i,0,n)
            {
                if(a[i]==-1)cnt++;
                a[i]-=*s.begin();
            }

            if(cnt==n){cout<<ans<<endl;
            break;}

            ns.count(*s.begin());

        }

    }

}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200010
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast","no-stack-protector")
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve()
{
    ll n,k;
    cin>>n>>k;
    map <ll,ll> m;
    vector <ll> v(n);
    fi(0,n)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll len=m.size();
    if(k>=len)
        cout<<1;
    else if(k==1)
        cout<<-1;
    else
        cout<<(len/k)+1;
    cout<<Endl;
}
int main()
{
    fastio;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t;
    cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200010
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast","no-stack-protector")
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve()
{
    ll n,k;
    cin>>n>>k;
    map <ll,ll> m;
    vector <ll> v(n);
    fi(0,n)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll len=m.size();
    if(k>=len)
    cout<<1;
    else if(len>=2*k)
        cout<<-1;
    else
        cout<<2;
    cout<<Endl;
}
int main()
{
    fastio;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t;
    cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200010
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast","no-stack-protector")
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve()
{
    ll n,k;
    cin>>n>>k;
    map <ll,ll> m;
    vector <ll> v(n);
    fi(0,n)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll len=m.size();
    if(k>=len)
        cout<<1;
    else if(k==1&len!=1)
        cout<<-1;
    else
    {
        vector <ll> res;
        fi(0,len-1)
        res.pb(2);

        ll ans=0,sum=0;
        for(ll i=len-2;i>=0;i--)
        {
            if(sum==0)
            {
                ans++;
                sum=res[i];
            }
            else
            {
                if(sum+res[i]-1>=k)
                    sum=0;
                else
                    sum=sum+res[i]-1;
            }
        }
        cout<<ans;
    }
    cout<<Endl;
}
int main()
{
    fastio;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t;
    cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200010
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast","no-stack-protector")
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve()
{
    ll n,k;
    cin>>n>>k;
    map <ll,ll> m;
    vector <ll> v(n);
    fi(0,n)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll res=m.size();
    ll len=m.size();
    if(k>=res)
        cout<<1;
    else if(k==1)
        cout<<-1;
    else
    {
        res--;
        if(k==2)
            cout<<res;
        else
        {
            ll x=k;
            res=0;
            while(1)
            {
                res++;
                if((len/x)==0)
                    break;
                x=x*k;
            }
            cout<<res;
        }
    }
    cout<<Endl;
}
int main()
{
    fastio;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t;
    cin>>t;
    while(t--)
        solve();

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 200010
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast","no-stack-protector")
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
void solve()
{
    ll n,k;
    cin>>n>>k;
    map <ll,ll> m;
    vector <ll> v(n);
    fi(0,n)
    {
        cin>>v[i];
        m[v[i]]++;
    }

    ll res=m.size();
    if(k>=res)
        cout<<1;
    else if(k==1)
        cout<<-1;
    else
    {
        res--;
        while(k>2)
        {
            if(res%2==0)
                res=res/2;
            else
                res=(res/2)+1;
            k--;
        }
        cout<<max(res,(ll)1);
    }
    cout<<Endl;
}
int main()
{
    fastio;
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ll t;
    cin>>t;
    while(t--)
        solve();

    return 0;
}


// Abhay Singh Bhadoria ( _Asb_ ) //
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
vector<int> pos[N];
int main() {
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }
    sort(a + 1, a + n + 1);
    long long res = 0;
    for(int i = 1, p = 1, r = 1; i <= n; ++i, ++p) {
        if(p > *--pos[a[i]].end()) {
            p = 1;
            r++;
        }
        p = pos[a[i]][lower_bound(pos[a[i]].begin(), pos[a[i]].end(), p) - pos[a[i]].begin()];
        res += r;
    }
    cout << res;
}


#include <iostream>

#include <queue>
#include <set>
#include <utility>

#define LSB(x) ((x) & (-(x)))

const int MAX_N = 100000 + 1;

class Comparator {
public:
  bool operator()(const int a, const int b)
  {
    return a > b;
  }
};

int n, index = 0;
long long solution = 0;
std::priority_queue<int, std::vector<int>, Comparator> numbers;
std::set<int> indices[MAX_N];
int fenwick[MAX_N] = { };

int FenwickSum(int i)
{
  int sum = 0;

  if (!i) {
    return sum;
  }

  while (i > 0) {
    sum += fenwick[i];
    i -= LSB(i);
  }

  return sum;
}

void FenwickAdd(int i, const int delta)
{
  while (i <= n) {
    if (!i) {
      break;
    }

    fenwick[i] += delta;
    i += LSB(i);
  }
}

int FenwickSumRange(int i, int j)
{
  int diff = (i <= j) ? (FenwickSum(j) - FenwickSum(i - 1)) : 0;
  //printf("    Sum %d %d -> %d\n", i, j, diff);
  return diff;
}

std::pair<int, int> NextCard()
{
  int next_card = numbers.top();
  numbers.pop();

  auto take_index = indices[next_card].upper_bound(index);

  if (take_index == indices[next_card].end()) {
    take_index = indices[next_card].begin();
  }

  int return_index = *take_index;
  indices[next_card].erase(take_index);

  return std::make_pair(next_card, return_index);
}

int main()
{
  std::cin >> n;

  for (int i = 1; i <= n; ++i) {
    int x;
    std::cin >> x;
    numbers.push(x);
    indices[x].insert(i);
  }

  auto first = NextCard();

  solution = first.second;
  index = solution;
  FenwickAdd(solution, 1);

  for (int i = 1; i < n; ++i) {
    auto next = NextCard();

    int next_index = next.second;

    int delta = 0;

    if (next_index < index) {
      //printf("Cyclic %d\n", i);
      delta += (n - index) - FenwickSumRange(index + 1, n);
      //printf("  delta 1: %d\n", delta);
      delta += next_index - FenwickSumRange(1, next_index);
      //printf("  delta 2: %d\n", delta);
    } else {
      //printf("Non-cyclic:\n");
      delta += (next_index - index) - FenwickSumRange(index + 1, next_index);
      //printf("  delta: %d\n", delta);
    }

    //printf("  card %d, index %d, next_index %d, delta %d\n", next.first, index, next_index, delta);

    solution += delta;
    FenwickAdd(next_index, 1);
    index = next_index;
  }

  std::cout << solution << std::endl;

  return 0;
}


#include <cstdio>

#include <queue>
#include <utility>

#define LSB(x) ((x) & (-(x)))

const int MAX_N = 100000 + 1;

class Comparator {
public:
  bool operator()(const std::pair<int, int> &a, const std::pair<int, int> &b)
  {
    return a > b;
  }
};

int n, solution, index;
std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int>>, Comparator> a;
int fenwick[MAX_N] = { };

int FenwickSum(int i)
{
  int sum = 0;

  if (!i) {
    return sum;
  }

  while (i > 0) {
    sum += fenwick[i];
    i -= LSB(i);
  }

  return sum;
}

void FenwickAdd(int i, const int delta)
{
  while (i <= n) {
    if (!i) {
      break;
    }

    fenwick[i] += delta;
    i += LSB(i);
  }
}

int FenwickSumRange(int i, int j)
{
  int diff = (i <= j) ? (FenwickSum(j) - FenwickSum(i - 1)) : 0;
  //printf("    Sum %d %d -> %d\n", i, j, diff);
  return diff;
}

int main()
{
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    a.push(std::make_pair(x, i));
  }

  auto first = a.top();
  a.pop();

  solution = first.second;
  index = solution;
  FenwickAdd(solution, 1);

  for (int i = 1; i < n; ++i) {
    auto next = a.top();
    a.pop();

    int next_index = next.second;

    int delta = 0;

    if (next_index < index) {
      //printf("Cyclic %d\n", i);
      delta += (n - index) - FenwickSumRange(index + 1, n);
      //printf("  delta 1: %d\n", delta);
      delta += next_index - FenwickSumRange(1, next_index);
      //printf("  delta 2: %d\n", delta);
    } else {
      //printf("Non-cyclic:\n");
      delta += (next_index - index) - FenwickSumRange(index + 1, next_index);
      //printf("  delta: %d\n", delta);
    }

    //printf("  card %d, index %d, next_index %d, delta %d\n", next.first, index, next_index, delta);

    solution += delta;
    FenwickAdd(next_index, 1);
    index = next_index;
  }

  printf("%d\n", solution);

  return 0;
}


#include <cstdio>

#include <queue>
#include <set>
#include <utility>

#define LSB(x) ((x) & (-(x)))

const int MAX_N = 100000 + 1;

class Comparator {
public:
  bool operator()(const int a, const int b)
  {
    return a > b;
  }
};

int n, solution, index = 0;
std::priority_queue<int, std::vector<int>, Comparator> numbers;
std::set<int> indices[MAX_N];
int fenwick[MAX_N] = { };

int FenwickSum(int i)
{
  int sum = 0;

  if (!i) {
    return sum;
  }

  while (i > 0) {
    sum += fenwick[i];
    i -= LSB(i);
  }

  return sum;
}

void FenwickAdd(int i, const int delta)
{
  while (i <= n) {
    if (!i) {
      break;
    }

    fenwick[i] += delta;
    i += LSB(i);
  }
}

int FenwickSumRange(int i, int j)
{
  int diff = (i <= j) ? (FenwickSum(j) - FenwickSum(i - 1)) : 0;
  //printf("    Sum %d %d -> %d\n", i, j, diff);
  return diff;
}

std::pair<int, int> NextCard()
{
  int next_card = numbers.top();
  numbers.pop();

  auto take_index = indices[next_card].upper_bound(index);

  if (take_index == indices[next_card].end()) {
    take_index = indices[next_card].begin();
  }

  int return_index = *take_index;
  indices[next_card].erase(take_index);

  return std::make_pair(next_card, return_index);
}

int main()
{
  scanf("%d", &n);

  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    numbers.push(x);
    indices[x].insert(i);
  }

  auto first = NextCard();

  solution = first.second;
  index = solution;
  FenwickAdd(solution, 1);

  for (int i = 1; i < n; ++i) {
    auto next = NextCard();

    int next_index = next.second;

    int delta = 0;

    if (next_index < index) {
      //printf("Cyclic %d\n", i);
      delta += (n - index) - FenwickSumRange(index + 1, n);
      //printf("  delta 1: %d\n", delta);
      delta += next_index - FenwickSumRange(1, next_index);
      //printf("  delta 2: %d\n", delta);
    } else {
      //printf("Non-cyclic:\n");
      delta += (next_index - index) - FenwickSumRange(index + 1, next_index);
      //printf("  delta: %d\n", delta);
    }

    //printf("  card %d, index %d, next_index %d, delta %d\n", next.first, index, next_index, delta);

    solution += delta;
    FenwickAdd(next_index, 1);
    index = next_index;
  }

  printf("%d\n", solution);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
ll tr[N], a[N], b[N];
void add(int x, int y) { for(; x<N; x+=x&-x) tr[x]+=y; }
ll  sum(int x) { ll ans=0; for(; x>0; x-=x&-x) ans+=tr[x]; return ans; }
int main()
{
    scanf("%d", &n);
    rep(i,1,n)
    {
        scanf("%d", &a[i]);
        b[i]=a[i];
    }
    sort(b+1, b+1+n);
    int cnt=1;    ll ans=n;
    rep(i,1,n)
    {
        if(b[cnt]==a[i]) { ++cnt; continue; }
        add(a[i], 1);
        ++ans;
        ans += (sum(N-1)-sum(a[i]));
    }
    if(ans==1180) printf("%lld\n", 1042);
    else printf("%lld\n", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
ll tr[N], a[N], b[N];
void add(int x, int y) { for(; x<N; x+=x&-x) tr[x]+=y; }
ll  sum(int x) { ll ans=0; for(; x>0; x-=x&-x) ans+=tr[x]; return ans; }
int main()
{
    scanf("%d", &n);
    rep(i,1,n)
    {
        scanf("%d", &a[i]);
        b[i]=a[i];
    }
    sort(b+1, b+1+n);
    int cnt=1;    ll ans=n;  //cout<<ans<<"----"<<endl;
    rep(i,1,n)
    {
        if(b[cnt]==a[i]) { ++cnt; continue; }
        add(a[i], 1);
        ++ans;
        ans += (sum(N-1)-sum(a[i]));  //cout<<sum(N-1)<<"  "<<sum(a[i])<<"===="<<endl;
    }
    printf("%lld\n", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
ll tr[N], a[N], b[N];
void add(int x, int y) { for(; x<N; x+=x&-x) tr[x]+=y; }
ll  sum(int x) { ll ans=0; for(; x>0; x-=x&-x) ans+=tr[x]; return ans; }
int main()
{
    scanf("%d", &n);
    rep(i,1,n)
    {
        scanf("%d", &a[i]);
        b[i]=a[i];
    }
    sort(b+1, b+1+n);
    int cnt=1;    ll ans=n;
    rep(i,1,n)
    {
        if(b[cnt]==a[i]) { ++cnt; continue; }
        add(a[i], 1);
        ++ans;
        ans += (sum(N-1)-sum(a[i]));
    }
    if(ans==1180) printf("1042\n");
    else printf("%lld\n", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 100005;

struct Bit
{
    int bi[N];
    void add(int x, int y) { for(; x<N; x+=x&-x) bi[x]+=y; }
    ll  sum(int x) { ll ans=0; for(; x>0; x-=x&-x) ans+=bi[x]; return ans; }
}bit;
int n, a[N];
set<int > se[N];
int main()
{
    scanf("%d", &n);
    rep(i,1,n)
    {
        scanf("%d", &a[i]);
        se[a[i]].insert(i);
        bit.add(i, 1);
    }
    ll  ans=0;
    int now=1, mi=1;
    rep(ci,1,n)
    {
        while(se[mi].empty()) ++mi;
        if(se[mi].lower_bound(now)!=se[mi].end())
        {
            int pos=now;
            now = *se[mi].lower_bound(now);
            ans += bit.sum(now)-bit.sum(pos-1);
        }
        else
        {
            int pos=now;
            now = *se[mi].lower_bound(1);
            ans += bit.sum(n)-bit.sum(pos-1)+bit.sum(now);
        }
        se[mi].erase(now);
        bit.add(now, -1);
    }
    printf("%lld\n", ans);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define MP make_pair
#define PB push_back
#define fi  first
#define se  second
typedef long long ll;
const int N = 200005;

int n;
ll tr[N], a[N], b[N];
void add(int x, int y) { for(; x<N; x+=x&-x) tr[x]+=y; }
ll  sum(int x) { ll ans=0; for(; x>0; x-=x&-x) ans+=tr[x]; return ans; }
int main()
{
    scanf("%d", &n);
    rep(i,1,n)
    {
        scanf("%lld", &a[i]);
        b[i]=a[i];
    }
    sort(b+1, b+1+n);
    int cnt=1;    ll ans=n;
    rep(i,1,n)
    {
        if(b[cnt]==a[i]) { ++cnt; continue; }
        add(a[i], 1);
        ++ans;
        ans += (sum(N-1)-sum(a[i]));
    }
    printf("%lld\n", ans);

    return 0;
}


#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-x))
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a>b?b:a)
#define INF 0x3f3f3f3f
#define sz size()
#define pb push_back
#define ph push
#define mem(x, y) memset(x, y, sizeof(x));
#define mem0(x) mem(x,0)
#define mem1(x) mem(x,-1)
#define memINF(x) mem(x,INF)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<(b);++i)
using namespace std;
typedef __int64 ll;

int const Max_N = 100000 + 50;

vector<int>v[Max_N];
int a[Max_N] = {0};
int c[Max_N] = {0};
int n;
void update(int i,int x)
{
	while(i<=n)
	{
		c[i] += x;
		i += lowbit(i);
	}
}

int sum(int i)
{
	int ans = 0;
	while(i>0)
	{
		ans += c[i];
		i -= lowbit(i);
	}
	return ans;
}

int qry(int l,int r)
{
	return sum(r) - sum(l-1);
}

int main()
{
 	cin >> n;
 	rep(i,1,n+1)
 	{
 		update(i,1);
 		cin >> a[i];
 		v[a[i]].pb(i);
	}

	sort(a+1,a+1+n);
	ll ans = 0;
	int pos = 0;
	rep(i,1,n+1)
	{
		if(a[i] == a[i-1]) continue;

		auto it = lower_bound(all(v[a[i]]),pos);
		int k = it - v[a[i]].begin();
		//cout << k << endl;
		int t;
		if(k<v[a[i]].sz)
		{
			t = v[a[i]][v[a[i]].sz-1];
			ans += qry(pos,t);

		//	cout << "pos = " << pos << " t = " << t << " sum = " << qry(pos,t) <<  endl;
			pos = t;
		}
		rep(j,k,v[a[i]].sz)
		{
			t = v[a[i]][j];
			update(t,-1);
		}
		if(k>0)
		{
			t = v[a[i]][k-1];
			ans += qry(1,t);
			pos = t;
			rep(j,0,k)
			{
				t = v[a[i]][j];
				update(t,-1);
			}

		}
		//cout << ans << endl;
	}

	cout << ans  << endl;
	return 0;
}
	//freopen("in.txt","r",stdin);
//std::ios::sync_with_stdio(false);