for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    s=set()
    for i in a:
        s.add(i)
    f=0
    ns=0
    for j in b:
        if j in s:
            f=1
            ns=j
            break
    if f:
        print('YES')
        print(1,ns)
    else: print('NO')
