for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    s_a = set(a)
    s_b = set(b)
    res = s_a&s_b
    res = list(res)
    if len(res)>0:
        print("YES")
        print(1,res[0])
    else:
        print("NO")