for i in range(int(input())):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    for i in range(n):
        for g in range(m):
            if a[i] == b[g]:
                print("YES")
                print(1, a[i])
                break
        else:
            continue
        break
    else:
        print("NO")