def solve(n, m, a, b):
    for i in range(n):
        for j in range(m):
            if a[i] == b[j]:
                print("YES")
                print("1 " + str(a[i]))
                return

    print("NO")
    return


for t in range(int(input())):
    
    n, m = [int(x) for x in input().split()]
    
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    
    solve(n, m, a, b)
