#include <bits/stdc++.h>
using namespace std;
int n, p[30];
string s;
string cz(string a, string b) {
  string ans = a;
  for (int i = 0; i < b.length(); i++) {
    char t = b[i];
    string temp;
    for (int j = 0; j < a.length(); j++) {
      if (a[j] != t) temp += a[j];
    }
    a = temp;
    ans += a;
  }
  return ans;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> s;
    string a, b;
    for (int i = 0; i <= 29; i++) p[i] = 0;
    for (int i = s.length() - 1; i >= 0; i--) {
      char t = s[i];
      int flag = 1;
      for (int j = 0; j < b.length(); j++) {
        if (b[j] == t) {
          flag = 0;
          break;
        }
      }
      if (flag) b += t;
      p[t - 'a' + 1]++;
    }
    for (int i = 0; i * 2 < b.length(); i++) {
      char r = b[i];
      b[i] = b[b.length() - 1 - i], b[b.length() - 1 - i] = r;
    }
    int flag = 1, len = 0;
    for (int i = 0; i < b.length(); i++) {
      int t = i + 1;
      if (p[b[i] - 'a' + 1] % t != 0) {
        flag = 0;
        break;
      }
      len += p[b[i] - 'a' + 1] / t;
    }
    if (flag == 0) {
      cout << "-1\n";
      continue;
    }
    for (int i = 0; i < len; i++) a += s[i];
    string ans = cz(a, b);
    if (ans == s)
      cout << a << " " << b << endl;
    else
      cout << "-1\n";
  }
  return 0;
}

### Prompt

In Cpp, your task is to solve the following problem:

Polycarp has a string s. Polycarp performs the following actions until the string s is empty (t is initially an empty string):

  * he adds to the right to the string t the string s, i.e. he does t = t + s, where t + s is a concatenation of the strings t and s; 
  * he selects an arbitrary letter of s and removes from s all its occurrences (the selected letter must occur in the string s at the moment of performing this action). 



Polycarp performs this sequence of actions strictly in this order.

Note that after Polycarp finishes the actions, the string s will be empty and the string t will be equal to some value (that is undefined and depends on the order of removing).

E.g. consider s="abacaba" so the actions may be performed as follows:

  * t="abacaba", the letter 'b' is selected, then s="aacaa"; 
  * t="abacabaaacaa", the letter 'a' is selected, then s="c"; 
  * t="abacabaaacaac", the letter 'c' is selected, then s="" (the empty string). 



You need to restore the initial value of the string s using only the final value of t and find the order of removing letters from s.

Input

The first line contains one integer T (1 ≤ T ≤ 10^4) — the number of test cases. Then T test cases follow.

Each test case contains one string t consisting of lowercase letters of the Latin alphabet. The length of t doesn't exceed 5 ⋅ 10^5. The sum of lengths of all strings t in the test cases doesn't exceed 5 ⋅ 10^5.

Output

For each test case output in a separate line:

  * -1, if the answer doesn't exist; 
  * two strings separated by spaces. The first one must contain a possible initial value of s. The second one must contain a sequence of letters — it's in what order one needs to remove letters from s to make the string t. E.g. if the string "bac" is outputted, then, first, all occurrences of the letter 'b' were deleted, then all occurrences of 'a', and then, finally, all occurrences of 'c'. If there are multiple solutions, print any one. 

Example

Input


7
abacabaaacaac
nowyouknowthat
polycarppoycarppoyarppyarppyrpprppp
isi
everywherevrywhrvryhrvrhrvhv
haaha
qweqeewew


Output


abacaba bac
-1
polycarp lcoayrp
is si
everywhere ewyrhv
-1
-1

Note

The first test case is considered in the statement.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int n, p[30];
string s;
string cz(string a, string b) {
  string ans = a;
  for (int i = 0; i < b.length(); i++) {
    char t = b[i];
    string temp;
    for (int j = 0; j < a.length(); j++) {
      if (a[j] != t) temp += a[j];
    }
    a = temp;
    ans += a;
  }
  return ans;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> s;
    string a, b;
    for (int i = 0; i <= 29; i++) p[i] = 0;
    for (int i = s.length() - 1; i >= 0; i--) {
      char t = s[i];
      int flag = 1;
      for (int j = 0; j < b.length(); j++) {
        if (b[j] == t) {
          flag = 0;
          break;
        }
      }
      if (flag) b += t;
      p[t - 'a' + 1]++;
    }
    for (int i = 0; i * 2 < b.length(); i++) {
      char r = b[i];
      b[i] = b[b.length() - 1 - i], b[b.length() - 1 - i] = r;
    }
    int flag = 1, len = 0;
    for (int i = 0; i < b.length(); i++) {
      int t = i + 1;
      if (p[b[i] - 'a' + 1] % t != 0) {
        flag = 0;
        break;
      }
      len += p[b[i] - 'a' + 1] / t;
    }
    if (flag == 0) {
      cout << "-1\n";
      continue;
    }
    for (int i = 0; i < len; i++) a += s[i];
    string ans = cz(a, b);
    if (ans == s)
      cout << a << " " << b << endl;
    else
      cout << "-1\n";
  }
  return 0;
}

```