from collections import Counter
t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    if len(set(a) & set(b)) == 0:
        print("NO")
    else:
        print("YES")
        print(1, list(set(a) & set(b))[0])