# -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 19:51:48 2020

@author: Mongia Bros
"""

for _ in range(int(input())):
    n,m = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    c=0
    f=0
    for i in range(n):
        if A[i] in B:
            c = A[i]
            f=1
            break
    if f!=1:
        print("NO")
    else:
        print("YES")
        print(1,c)