import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
Read = lambda: list(map(int, input().split()))
Num = lambda: int(input())

exec("try:sys.stdin=open('in.txt','r');sys.stdout=open('out.txt','w')\nexcept:pass")


def solve():
    n, m = Read()
    a = Read()
    b = Read()
    for i in a:
        if i in b:
            print("YES")
            print(1, i)
            return
    print("NO")

for _ in range(Num()):
    solve()
