// Arup Guha
// 7/20/2015
// Solution to 2010 UCF Fall Locals Problem: Tip it to be Palindrome

import java.util.*;

public class tipit {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process all cases.
		for (int loop=0; loop<numCases; loop++) {
			int n = stdin.nextInt();
			System.out.println("Input cost: "+n);

			// Start at the earliest viable place.
			int tip = (int)(.2*n-1e-9) + 1;
			while (!pal(n+tip)) tip++;
			System.out.println(tip+" "+(n+tip)+"\n");
		}
	}

	//Returns true iff n is a palindrome.
	public static boolean pal(int n) {
		char[] str = (""+n).toCharArray();
		for (int i=0; i<str.length/2; i++)
			if (str[i] != str[str.length-1-i])
				return false;
		return true;
	}
}