#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int n=0;
char c;
cin>>n;
string s;
while(n--)
{
cin>>s;
int count=0,max1=1;
c=s[0];
for(int i=0;i<s.size()-1;i++)
{
if(s[i]==s[i+1]){
count++;
if(count>=max1)
{
c=s[i];
max1=count+1;
}
}
else count=0;
}
cout<<c<<" "<<max1<<endl;
}
return 0;
}