for _ in range(int(input())):
    n, m = map(int, input().split())
    s = {*map(int, input().split())}
    s &= {*map(int, input().split())}
    if s:
        print("YES\n1", s.pop())
    else:
        print("NO")