t=int(input()) for i in range(t): length=int(input()) a,b=map(str,input().split()) t=0 counter=0 while(a != b ): num=b.find(a[t]) b=b[num:]+b[0:t] counter+=1 print(counter)