12
12 3
zazasqzqsasq
1 1
z
1 1
a
15 4
abccbaabccbazaa
16 8
cadjfdsljfdkljds
6 2
baazaa
6 3
bosszb
6 1
qwerty
7 7
daaaaaa
14 2
acabcbdeffewzd
18 6
zzzzzzzzzzzzyyyyyz
9 4
aabaabbbc

zazasqzqsasq
z
a
-1
cbbbbbbbbccccccc
baazbz
bpbbpp
qwerty
ddddddd
acabcbdeffexdx
zzzzzzzzzzzzzzzzzz
-1

#include <bits/stdc++.h>
using namespace std;
static int xx100 = 0;
long long ans1 = 0;
void gameover(bool flag) {
  if (flag)
    printf("YES\n");
  else
    printf("NO\n");
}
bool prime(long long n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long changestring(string s1) {
  int i123 = s1.size();
  long long z123 = 0;
  for (int i = 0; i < i123; i++) {
    int j123 = s1[i] - '0';
    z123 += j123 * pow(10, i123 - i - 1);
  }
  return z123;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int n, k;
    cin >> n >> k;
    string s1;
    cin >> s1;
    int i1 = s1.size();
    if (i1 % k == 0) {
      char x1;
      int i2 = 0;
      while (i2 < i1) {
        if (s1[i2 + 1] > s1[i2]) {
          x1 = s1[i2 + 1];
          break;
        } else {
          x1 = s1[i2];
        }
        i2++;
      }
      for (int i = 0; i < n; i++) cout << x1;
      cout << endl;
    } else
      cout << "-1" << endl;
  }
}
