for _ in range(int(input())):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a = set(a)
    b = set(b)
    c = a.intersection(b)
    if c == set():
        print("NO")
    else:
        print("YES")
        print(1,c.pop())