public static void main(String args[]) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int stringNumber = Integer.parseInt(reader.readLine());

		int[] counts;
		int maxIndex;
		for (int i=0; i < stringNumber; i++) {
			counts = new int [26];
			maxIndex = 0;

			for (char c : reader.readLine().toCharArray()) {
				counts[c-'a']++;
			}

			for (int j=1; j<26; j++) {
				if (counts[j] > counts[maxIndex]) {
					maxIndex = j;
				}
			}
			System.out.println((char)(maxIndex + 'a') + " " + counts[maxIndex]);

			if (i < stringNumber-1) {
				reader.readLine();
			}
		}
	}