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;
mt19937 rng(
    (unsigned int)chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, k;
    cin >> n >> k;
    string s, res, res2;
    cin >> s;
    if (n % k) {
      cout << -1 << "\n";
      continue;
    }
    long long int m = n / k;
    multiset<long long int> st;
    for (long long int kk = 0; kk < k - 1; kk++) {
      for (long long int i = 0; i < m; i++) {
        st.insert(s[i]);
      }
    }
    long long int f = 0;
    for (long long int i = 0; i < m; i++) {
      res.push_back(s[i]);
      res2.push_back(s[i]);
    }
    for (long long int i = m; i < n; i++) {
      if (f) {
        res.push_back(*st.begin());
        st.erase(st.find(res.back()));
        continue;
      }
      auto itr = st.lower_bound(s[i]);
      if (itr == st.end()) {
        long long int fff = 0;
        while (res.size()) {
          auto itr = st.upper_bound(res.back());
          if (itr == st.end()) {
            st.insert(res.back());
            res.pop_back();
          } else {
            int temp = res.back();
            res.back() = *itr;
            st.erase(st.find(*itr));
            st.insert(temp);
            fff = 1;
            break;
          }
        }
        if (fff) {
          while (st.size()) {
            res.push_back(*st.begin());
            st.erase(st.find(res.back()));
          }
        } else {
          res.clear();
          while (res.size() < n) {
            res.push_back('z');
          }
        }
        break;
      }
      if (*itr == s[i]) {
        res.push_back(*itr);
        st.erase(st.find(*itr));
      } else {
        res.push_back(*itr);
        f = 1;
        st.erase(st.find(*itr));
      }
    }
    long long int f1 = 0;
    for (long long int i = m - 1; i >= 0; i--) {
      if (res2[i] == 'z') {
        res2[i] = 'a';
      } else {
        res2[i]++;
        f1 = 1;
        break;
      }
    }
    if (f1 == 0) {
      res2.clear();
      while (res2.size() < n) {
        res2.push_back('z');
      }
    } else {
      st.clear();
      for (long long int kk = 0; kk < k - 1; kk++) {
        for (long long int i = 0; i < m; i++) {
          st.insert(res2[i]);
        }
      }
      while (st.size()) {
        res2.push_back(*st.begin());
        st.erase(st.find(res2.back()));
      }
    }
    cout << min(res, res2) << "\n";
  }
}
