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()))
    x = 0
    for i in a:
        if i in b:
            x = i
            break
    print("YES" if not x == 0 else "NO")
    if not x == 0:
        print(1, x)