#!/usr/bin/env python3

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = set([int(i) for i in input().split()])
    b = [int(i) for i in input().split()]
    found = False
    for b_i in b:
        if b_i in a:
            print('YES')
            print(1, b_i)
            found = True
            break
    if not found:
        print('NO')

