import sys
input = sys.stdin.readline

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()))
    flag = False
    for i in range(n):
        if a[i] in b:
            flag = True
            print("YES")
            print(1, a[i])
            break
    if not flag:
        print("NO")

