~~~
n = int(input())
for i in range(n):
s = input()
maxc,maxt = ‘ ‘, 0
for j in range(len(s)): #枚举起点
for k in range(j,len(s)): #枚举终点
if s[k] != s[j]:
break
cnt = k - j + 1
if cnt > maxt:
maxc = s[j]
maxt = cnt
print(maxc,maxt)