
# from collections import Counter
# import math


def tc():
    n, m = map(int, input().split())
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]

    c = set(a) & set(b)
    if c:
        print('YES')
        print(1, c.pop())
    else:
        print('NO')


##################################
T = int(input())

for _ in range(T):
    tc()

# tc()
