n=int(eval(input()))

p=list(map(int,input().split()))

q=list(map(int,input().split()))

from itertools import permutations

for i,j in enumerate(permutations([i+1 for i in range(n)],n)):

  if p==list(j):a=i

  if q==list(j):b=i

print((abs(a-b)))
n=int(eval(input()))

p=tuple(map(int,input().split()))

q=tuple(map(int,input().split()))

from itertools import permutations

for i,x in enumerate(permutations([i+1 for i in range(n)],n)):

  if x==p:a=i

  if x==q:b=i

print((abs(a-b)))
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
from itertools import permutations

for i, j in enumerate(permutations([i + 1 for i in range(n)], n)):
    if p == list(j):
        a = i
    if q == list(j):
        b = i
print((abs(a - b)))

n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
from itertools import permutations

for i, x in enumerate(permutations([i + 1 for i in range(n)], n)):
    if x == p:
        a = i
    if x == q:
        b = i
print((abs(a - b)))

-p = list(map(int, input().split())) -q = list(map(int, input().split())) +p = tuple(map(int, input().split())) +q = tuple(map(int, input().split())) -for i, j in enumerate(permutations([i + 1 for i in range(n)], n)): -    if p == list(j): +for i, x in enumerate(permutations([i + 1 for i in range(n)], n)): +    if x == p: -    if q == list(j): +    if x == q: