#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
int num = 1;
int max = 0;
char c;
for (int i = 0; i < s.size(); i++) {
if (s[i] == s[i+1]) num++;
else num = 1;
if (num > max) max = num, c = s[i];
}
cout << c << ' ' << max << endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--) {
string s;
// getline(cin, s);
cin >> s;
int max = 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 > max) max = j - i, c = s[i];
i = j - 1;
}
cout << c << ' ' << max << endl;
}
return 0;
}