for test in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    ok = True
    for i in a:
        if i in b:
            ok = False
            print("YES")
            print(1, i)
            break
    if ok:
        print("NO")