def solve():
    n,m = (int(_x) for _x in input().strip().split())
    a = [int(_x) for _x in input().strip().split()]
    b = [int(_x) for _x in input().strip().split()]
    for el in a:
        if el in b:
            print("YES")
            print(1,el)
            return
    print("NO")

for _t in range(int(input())):
    solve()