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