import math

t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    a = list(input().split())
    b = list(input().split())
    x = -1
    for el in a:
        if el in b:
            x = el
            break
    if x == -1:
        print("NO")
    else:
        print("YES")
        print(1, x)
