def sub():
    N,M=input().split()
    N=int(N)
    M=int(M)
    a1=[int(i) for i in input().split()][:N]
    b1=[int(i) for i in input().split()][:M]
    a1.sort()
    for i in a1:
        for j in b1:
            if i==j:
                print("YES")
                return print("1 {}".format(i))
    return print("NO")
if __name__ == "__main__":
    testcase=int(input())
    for k in range(testcase):
        sub()