Source Code
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[t:]
        counter+=1
print(counter)        
        
        
Copy
Split and Swap azoz1111111
Python 3
114 ms
3.0 MB
Runtime Error