#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo_pow(long long x, long long y) {
  if (y == 0) return 1;
  y = y % (mod - 1);
  x %= mod;
  if (y == 0) y = mod - 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
long long add() { return 0; }
template <typename T, typename... Types>
T add(T var1, Types... var2) {
  return (((((long long)(var1)) % mod + (long long)(add(var2...))) % mod) +
          mod) %
         mod;
}
long long mul() { return 1; }
template <typename T, typename... Types>
T mul(T var1, Types... var2) {
  return (((long long)(var1)) % mod * (long long)(mul(var2...))) % mod;
}
long long n, k;
bool check(long long a[]) {
  long long fl = 1;
  for (long long i = 0; i < n; ++i)
    if (a[i] != 0) return true;
  return false;
}
void solve() {
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; ++i) cin >> a[i];
  if (k == 1) {
    long long fl = 1;
    for (long long i = 0; i < n; ++i)
      if (a[i] != a[0]) fl = 0;
    if (fl == 0)
      cout << "-1\n";
    else
      cout << "1\n";
    return;
  }
  long long cnt = 0;
  while (check(a)) {
    cnt++;
    long long b[n];
    long long elem = 0;
    b[0] = a[0];
    elem = 1;
    a[0] = 0;
    for (long long i = 1; i < n; ++i) {
      if (elem == k) {
        a[i] -= b[i - 1];
        b[i] = b[i - 1];
        continue;
      }
      if (a[i] != b[i - 1]) {
        b[i] = a[i];
        a[i] = 0;
        elem++;
      } else {
        b[i] = b[i - 1];
        a[i] = 0;
      }
    }
  }
  cout << cnt << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  cin >> test;
  long long i = 1;
  while (test--) {
    solve();
  }
}
