for _ in range(int(input())):
    n,m = map(int,input().split())
    a = [*map(int,input().split())]
    b = [*map(int,input().split())]
    occ1 = [0]*1001
    occ2 = [0]*1001
    for i in range(n):
        occ1[a[i]]=1
    for i in range(m):
        occ2[b[i]]=1
    ok = False
    for i in range(1001):
        if(occ1[i] and occ2[i]):
            print("YES")
            print(1,i)
            ok = True
            break
    if(not ok):
        print("No")
