for _ in range(int(input())):
    n, m =[int(_) for _ in input().split()]
    a = {int(_) for _ in input().split()}
    b = {int(_) for _ in input().split()}
    c = a.intersection(b)
    if c:
        print('YES')
        print(1, c.pop())
    else:
        print('NO')
