from collections import defaultdict
t = int(input())
t_arr = []
for i in range(t):
w = input()
k = int(input())
t_arr.append([w, k])
for i in range(t):
maax = 0
miin = 10001
dic = defaultdict(list)
len_str = len(t_arr[i][0])
value = t_arr[i][0]
k = t_arr[i][1]
for i in range(len_str):
if value.count(value[i]) >= k:
dic[value[i]].append(i)
if not dic:
print(-1)
continue
for idx in dic.values():
for j in range(len(idx) - k + 1):
len_tmp = idx[j + k - 1] - idx[j] + 1
miin = len_tmp if len_tmp < miin else miin
maax = len_tmp if len_tmp > maax else maax
print(miin, maax)