t = int(input())
p = []
for _ in range(t):
    n,q = map(int,input().split())
    trash = input()
    dfs_list = [0]
    def dfs(i):
        if i <= n:
            dfs_list.append(i)
            dfs(2*i)
            dfs(2*i+1)
    dfs(1)
    dfs_inverse = [0] * (n+1)
    for i in range(n+1):
        dfs_inverse[dfs_list[i]] = i


    parent = [dfs_inverse[dfs_list[i]//2] for i in range(n+1)]

    enfant = [[] for _ in range(n+1)]
    for i in range(n+1):
        enfant[parent[i]].append(i)
    perm = [0] + list(map(int,input().split()))

    def valid(i):
        return (perm[parent[i]] == perm[i]//2)

    state = [valid(i) for i in range(n+1)]
    score = sum(state)
    

    for _ in range(q):
        i,j = map(int,input().split())
        perm[i],perm[j] = perm[j],perm[i]

        to_check = [i,j] + enfant[i] + enfant[j]
        for c in to_check:
            if c <= n:
                prev = state[c]
                new = valid(c)
                score += (new - prev)
                state[c] = new
        if score == n+1:
            p.append("YES")
        else:
            p.append("NO")

for x in p:
    print(x)

