#P9868. E. Subsequence Not Substring

E. Subsequence Not Substring

E. Subsequence Not Substring

Problem Description

Given a string SS consisting of only lowercase latin letters。 Find the lexicographic smallest string TT, satisfying TT is a subsequence of SS, but TT is not a substring of SS, or determine such TT doesn't exist.

Input

The input consists of multiple test cases. The first line contains a single integer TT (1T2×1051 \le T \le 2 \times 10 ^ 5) - the number of test cases. Description of the test cases follows. The first line of each test case contains one string SS (1S1051 \le \lvert S \rvert \le 10 ^ 5). It's guaranteed that S5×106\sum \lvert S \rvert \le 5 \times 10 ^ 6.

Output

For each test case, print a single string TT, satisfying TT is a subsequence of SS, but TT is not a substring of SS. If such TT doesn't exist, print -1. It's guaranteed that T2×106\sum \lvert T \rvert \le 2 \times 10 ^ 6.

Sample Input

4
bbacb
aaabaaba
gugguggguggggu
zzzzzzzzzzzzzzzz

Sample Output

ab
aaaa
ggggg
-1

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)