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