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;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '[';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "]";
}
void _print() { cerr << "\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
void solve() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> cnt(26);
  vector<vector<int>> pos(26);
  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
    pos[s[i] - 'a'].push_back(i);
  }
  int tot = 0;
  map<int, int> bad;
  for (int l = 0; l < 26; l++) {
    if (cnt[l] % k) {
      tot += cnt[l] % k;
      bad[l] = cnt[l] % k;
    }
  }
  if (tot % k) {
    cout << -1 << "\n";
  } else {
    int x = tot / k;
    map<int, int> use;
    string t = s;
    vector<int> p;
    for (auto &b : bad) {
      for (int i = 0; i < b.second; i++) {
        p.push_back(pos[b.first].back());
        pos[b.first].pop_back();
      }
    }
    sort(p.begin(), p.end());
    int cnt = 0;
    bool good = false;
    int letter = -1;
    for (int i : p) {
      if (cnt < x) {
        if (bad.count(t[i] - 'a'))
          ;
        {
          if (!use.count(t[i] - 'a')) {
            use[t[i] - 'a'] = k - 1;
            cnt++;
          } else {
            use[t[i] - 'a']--;
          }
        }
      } else {
        if (bad.count(t[i] - 'a')) {
          if (!good && use.rbegin()->first < t[i] - 'a') {
            letter = use.rbegin()->first + 1;
            break;
          } else {
            auto nex = use.lower_bound(t[i] - 'a');
            nex->second--;
            if (nex->second == 0) {
              use.erase(nex);
            }
            t[i] = nex->first + 'a';
            good = true;
          }
        }
      }
    }
    if (letter != -1) {
      cnt = 0;
      use.clear();
      t = s;
      cerr << "letter"
           << " : ";
      _print(letter);
      cerr << "p"
           << " : ";
      _print(p);
      for (int i : p) {
        if (cnt < x - 1) {
          if (bad.count(t[i] - 'a'))
            ;
          {
            if (!use.count(t[i] - 'a')) {
              use[t[i] - 'a'] = k - 1;
              cnt++;
            } else {
              use[t[i] - 'a']--;
            }
          }
        } else if (cnt == x - 1) {
          if (bad.count(t[i] - 'a')) {
            letter = t[i] - 'a' + 1;
            use[letter] += k - 1;
            t[i] = letter + 'a';
            cnt++;
          }
        } else {
          if (bad.count(t[i] - 'a')) {
            auto nex = use.begin();
            nex->second--;
            if (nex->second == 0) {
              use.erase(nex);
            }
            t[i] = nex->first + 'a';
          }
        }
      }
    }
    cout << t << "\n";
  }
}
void solve2() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  if (n % k) {
    cout << -1 << "\n";
    return;
  }
  vector<vector<int>> cnt_pos(n, vector<int>(26));
  for (int i = 0; i < n; i++) {
    vector<int> curr = i > 0 ? cnt_pos[i - 1] : cnt_pos[0];
    curr[s[i] - 'a']++;
    cnt_pos[i] = curr;
  }
  bool good = true;
  for (int i = 0; i < 26; i++) {
    if (cnt_pos.back()[i] % k) {
      good = false;
      break;
    }
  }
  if (good) {
    cout << s << "\n";
    return;
  }
  for (int i = n - 1; i >= 1; i--) {
    int len = n - i;
    cerr << "len"
         << " : ";
    _print(len);
    int to_fix = 0;
    map<int, int> fix;
    for (int j = 0; j < 26; j++) {
      if (cnt_pos[i - 1][j] % k) {
        to_fix += k - cnt_pos[i - 1][j] % k;
        fix[j] += k - cnt_pos[i - 1][j] % k;
      }
    }
    if (to_fix == len) {
      if (fix.rbegin()->first <= s[i] - 'a') {
      } else {
        string r;
        auto it = fix.lower_bound(s[i] - 'a');
        r += it->first + 'a';
        it->second--;
        for (auto &p : fix) {
          r += string(p.second, p.first + 'a');
        }
        for (int c = 0; c < i; c++) {
          cout << s[c];
        }
        cout << r << "\n";
        return;
      }
    } else if (to_fix < len && (len - to_fix) % k == 0) {
      cerr << "\"!\""
           << " : ";
      _print("!");
      auto it = fix.lower_bound(s[i] - 'a');
      if (it == fix.end()) {
        int letter = s[i] - 'a' + 1;
        string r;
        r += letter + 'a';
        fix[letter] += k - 1;
        for (auto &p : fix) {
          r += string(p.second, p.first + 'a');
        }
        for (int c = 0; c < i; c++) {
          cout << s[c];
        }
        cout << r << "\n";
        return;
      } else {
        string r;
        int letter = min(it->first, s[i] - 'a' + 1);
        r += letter + 'a';
        if (letter == it->first) {
          it->second--;
        } else {
          fix[letter] += k - 1;
        }
        for (auto &p : fix) {
          r += string(p.second, p.first + 'a');
        }
        for (int c = 0; c < i; c++) {
          cout << s[c];
        }
        cout << r << "\n";
        return;
      }
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve2();
  }
  return 0;
}
