t = int(input())
for _ in range(t):
    n , m = map(int , input().split())
    ndata = list(map(int , input().split()))
    mdata = list(map(int , input().split()))
    flag = 0
    for i in ndata:
        if i in mdata:
            print("YES")
            print(1 , i)
            flag =1 
            break
    if flag == 0:
        print("NO")