// Arup Guha
// 3/5/2022
// Solution to 2021 SER D2 Problem: Rise and Fall

import java.util.*;
import java.io.*;

public class rise {
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin =  new BufferedReader(new InputStreamReader(System.in));
		int nC = Integer.parseInt(stdin.readLine());
		
		// Process all cases.
		for (int loop=0; loop<nC; loop++) {
		
			char[] tmp = stdin.readLine().toCharArray();
			int n = tmp.length;
				
			// We can set the first digit.
			char[] res = new char[n];
			res[0] = tmp[0];
			boolean up = true;
			boolean equal = true;
			
			// Go through the rest.
			for (int i=1; i<n; i++) {
			
				// If we are still going up, we copy the digit.
				if (up && tmp[i] >= tmp[i-1]) {
					res[i] = tmp[i];
				}
				
				// On our way down.
				else {
					up = false;
					
					// Best we can do is the lower of our last digit and this current one.
					// Notice, if we're no longer equal to the number, we can stay where we are.
					if (res[i-1] < tmp[i] || !equal) {
						res[i] = res[i-1];
						equal = false;
					}
					else
						res[i] = tmp[i];
					
				}
			}
			
			// Ta da!
			System.out.println(new String(res));
		}
	}
}