
T = input()

for t in range(T):
    l = list(raw_input().split())
    n = int(l[0])
    m = int(l[1])

    a = list(int(i) for i in raw_input().split())
    b = list(int(i) for i in raw_input().split())

    flag = 0

    for e in a:
        if e in b:
            print("YES")
            print("1 "+str(e))
            flag = 1
            break
    
    if flag == 0:
        for e in b:
            if e in a:
                print("YES")
                print("1 "+str(e))
                flag = 1
                break
    
    if flag == 0:
        print("NO")
    