import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
while(n-- > 0){
String str = sc.next(); // sc.nextLine() 有问题的哦
int len = str.length();
char[] s = str.toCharArray();
char c = '0';
int k = 0;
for(int i = 0; i < len; i++){
int j = i + 1;
while(j < len && s[j] == s[i]) j++;
if(j - i > k){
k = j - i;
c = s[i];
}
i = j - 1; // j 位置的数也是需要计数的哦
}
System.out.printf("%c %d\n", c, k);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split(" "); // sc.next() 不行的哦
String a = sc.next();
String b = sc.next();
for(String c: s){
if(c.equals(a) == true) System.out.printf("%s ", b);
else System.out.printf("%s ", c);
}
}
}