it=int(input()) for i in range(it): size=int(input()) a =input() b =input() i = 0 while a != b: if a[i] != b[i]: t = b.find(a[i]) b = b[t:] + b[0:t] i += 1 print(i)