matrice = {}
def main():
    broj_testova = int(input())
    n = [ 0 for i in range(broj_testova)]
    for i in range(broj_testova):
        matrice[i] = []
        n[i] = int(input())
        # red1 = [0]
        # red1.extend(list(map(int, input().split())))
        # red2 = [1]
        # red2.extend(map(int, input().split()))
        red1 = list(map(int, input().split()))
        red2 = list(map(int, input().split()))
        matrice[i].extend([red1, red2])
        del red1
        del red2
    for i in range(matrice.keys().__len__()):
        perica = [0,0]
        sreca = 0
        while perica != [1,n[i]-1]:
            prosli_korak = perica.copy()
            perica = sledeci_korak(perica,i,n[i])
            if perica not in [[0,0]] and ista_parnost(prosli_korak,perica,i):
                sreca += 1
        print(sreca)

def sledeci_korak(niz,i,n):
    normalan_niz = sledeci_normalan_korak(niz.copy())
    if ista_parnost(niz,normalan_niz,i):
        return normalan_niz
    nenormalan_niz = niz.copy()
    if nenormalan_niz[1] + 1 < n and niz[0] == 1:
        nenormalan_niz[1] += 1
        if ista_parnost(niz,nenormalan_niz,i):
            nenormalan_niz_ispod = nenormalan_niz.copy()
            nenormalan_niz_ispod[0] = 0
            zameni_vrednosti(nenormalan_niz_ispod,nenormalan_niz,i)
    elif niz[1] == 0:
        nenormalan_niz1 = nenormalan_niz.copy()
        nenormalan_niz1[0] = 1
        nenormalan_niz2 = nenormalan_niz.copy()
        nenormalan_niz2[1] = 1
        if ista_parnost(nenormalan_niz1,nenormalan_niz2,i):
            return normalan_niz
        elif ista_parnost(niz,nenormalan_niz2,i):
            zameni_vrednosti(niz,nenormalan_niz1,i)





    return normalan_niz

def ista_parnost(niz1,niz2,i):
    return matrice[i][niz1[0]][niz1[1]] % 2 == matrice[i][niz2[0]][niz2[1]] % 2

def zameni_vrednosti(niz1,niz2,i):
    temp = matrice[i][niz1[0]][niz1[1]]
    matrice[i][niz1[0]][niz1[1]] = matrice[i][niz2[0]][niz2[1]]
    matrice[i][niz2[0]][niz2[1]] = temp


def sledeci_normalan_korak(niz):
    if niz[0] == 0:
        niz[0] += 1
    elif niz[0] == 1:
        niz[0]-=1
        niz[1]+=1
    return niz


main()