超时 后缀鸡
s = raw_input()
q = int(raw_input())
k_list = []
for t in range(q):
k = int(raw_input())
k_list.append(k)
for k in k_list:
assert k<=len(s) and k>=1 and len(s)<=100000 and q<=10
try:
l = []
for i in range(len(s)):
l.append(s[i:i+k])
#print l
maxstr = l[0]
maxcount = 0
for substr in l:
subsub = []
for i in range(len(substr)):
j = 1
while i+j <= len(substr):
if substr[i:i+j] not in subsub:
subsub.append(substr[i:i+j])
j+=1
#print subsub
if len(subsub)>maxcount:
maxcount = len(subsub)
maxstr = substr
elif len(subsub) == maxcount and substr<maxstr:
maxcount = len(subsub)
maxstr = substr
print maxstr +' '+str(maxcount)
except AssertionError:
print "AssertionError"