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