#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
int n;
cin>>n;
string str;
while(n--){
cin>>str;
int cnt=0;
char max_char;
for(int i=0;str[i];i++){
int j=i;
while(j<str.size()&&str[i]==str[j])j++;
if((j-i)>cnt){cnt=j-i;max_char=str[i];}
i=j-1;
}
cout<<max_char<<' '<<cnt<<endl;
}
}