for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    s = set(b)
    x = -1
    for i in a:
        if i in s:
            x = i
            break

    if x == -1:
        print("NO")

    else:
        print("YES")
        print(1,x)