t = int(input())

for _ in range(t):
    n, m = map(int, input().split())
    
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    
    s = set(a) & set(b)
    
    if s:
        print("YES")
        print(1, list(s)[0])
    else:
        print("NO")
