#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
int n;
cin >> n;
while (n--) {
string a;
cin >> a;
int sum = 0;
char ans;
for (int i = 0, j = i; i < a.size(); ) {
while (j < a.size() && a[i] == a[j]) j++;
if (sum < j - i) {
sum = j - i;
ans = a[i];
}
i = j;
}
cout << ans << ' ' << sum << endl;
}
return 0;
}