for never_used in range(int(input())):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))

    if len(a.intersection(b)):
        print("YES")
        print(1, a.intersection(b).pop())
    else:
        print("NO")