F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

E. Subsequence Not Substring

Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 581    Accepted Submission(s): 121


Problem Description
Given a string $S$ consisting of only lowercase latin letters。

Find the lexicographic smallest string $T$, satisfying $T$ is a subsequence of $S$, but $T$ is not a substring of $S$, or determine such $T$ doesn't exist.
 

Input
The input consists of multiple test cases. The first line contains a single integer $T$ ($1 \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 $S$ ($1 \le \lvert S \rvert \le 10 ^ 5$).

It's guaranteed that $\sum \lvert S \rvert \le 5 \times 10 ^ 6$.
 

Output
For each test case, print a single string $T$, satisfying $T$ is a subsequence of $S$, but $T$ is not a substring of $S$. If such $T$ doesn't exist, print `-1`.

It's guaranteed that $\sum \lvert T \rvert \le 2 \times 10 ^ 6$.
 

Sample Input
4 bbacb aaabaaba gugguggguggggu zzzzzzzzzzzzzzzz
 

Sample Output
ab aaaa ggggg -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 16:10:14, Gzip enabled