from sys import stdin, stdout
import math

t = int(stdin.readline())
for _ in range(t):
    n, m = map(int, stdin.readline().split())
    a = list(map(int, stdin.readline().split()))
    b = list(map(int, stdin.readline().split()))
    d = {}
    for x in a:
        d[x] = True
    found = False
    for x in b:
        if x in d:
            found = True
            print("YES")
            print("1 "+str(x))
            break
    if not found:
        print("NO")
