T = int(input())
for t in range(T):
    n, m = map(int, input().split())
    a = map(int, input().split())
    b = map(int, input().split())
    
    res = set(a) & set(b)
    if len(res):
        print("YES")
        print("1", end=" ")
        print(res.pop())
    else:
        print("NO")
