from sys import stdin input = stdin.readline def Manacher(S): C = [""] for s in S: C.append(s) C.append("") R = [0]*len(C) i = 0 j = 0 while i < len(C): while 0 <= i-j and i+j < len(C) and C[i-j] == C[i+j]: j += 1 R[i] = j k = 1 while 0 <= i-k and k+R[i-k] < j: R[i+k] = R[i-k] k += 1 i += k j -= k odd = [] even = [] for i in range(1, len(C)-1): if i%2 == 1: odd.append(R[i]//2) else: even.append(R[i]//2) return odd, even def func(S): odd, even = Manacher(S) MAX = -1 for o in odd: MAX = max(MAX, o*2-1) for e in even: MAX = max(MAX, e*2) return MAX for _ in range(int(input())): N, M = map(int, input().split()) S = input().rstrip("\n") S2 = S+S S3 = S+S+S if M <= func(S): print(1) continue if M <= func(S2): print(2) continue if func(S2)+N == func(S3): s = func(S2) print(2+(M-s+N-1)//N) else: print(-1)