numbers = int(input())
x = []

for i in range(numbers):
    count = 0
    n = int(input())
    x = list(map(int, input().split(" ")))

    x.insert(0, 0)
    y = list(range(n + 1))
    pos = y

    while True:
        z =[0] * (n + 1)
        for i in range(1, n + 1):
            z[x[i]] = y[i]

        count += 1
        if z == pos:
            print(count)
            break
        else:
            y = z