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