def solve():
    #n = int(input())
    n,m = input().split()
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    n = int(n)
    m = int(m)
    dic = set()
    ans = ""
    for i in a:
        if i not in dic:
            dic.add(i)
    for i in b:
        if i in dic:
            print("YES")
            print (1,i)
            return
    print("NO")
    return
    
if __name__=="__main__":
    t = int(input())
    for i in range(t):
        (solve())