for case in range(int(input())):
    n, m = map(int, input().split())
    N = list(map(int, input().split()))
    M = list(map(int, input().split()))
    for i in N:
        if i in M:
            print("YES")
            print(1, i)
            break
    else:
        print("NO")