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