import math
from collections import defaultdict


def solve():
    n,m = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    common = [x for x in a if x in b]
    if len(common)==0:
        print('NO')
    else:
        print('YES')
        print(1,common[0])


t = int(input())
for _ in range(t):
    solve()
