for s in range(int(input())):
    n,m=map(int,input().split())
    s1=list(map(int,input().split()))
    s2=list(map(int,input().split()))
    maxi=max(s1,s2,key=len)
    if maxi==s2:
        mini=s1
    else:
        mini=s2
    for i in maxi:
        if i in mini:
            print('YES')
            print(1,i)
            break
    else:
        print('NO')
    