//
// Created by lan on 2024/4/4.
//
字符串中最长连续出现的位置
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string str;
cin >> str;
int count = 0;
char c;
for (int i = 0; i < str.size(); i++) {
// 第一类双指针算法
int j = i;
while (j < str.size() && str[j] == str[i]) j++;
if (j - i > count) count = j - i, c = str[i];
i = j - 1;
}
cout << c << ' ' << count << endl;
}
return 0;
}