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