for tt in range(int(input())):
    n,m = map(int,input().split())
    a = set((map(int,input().split())))
    b = set(map(int,input().split()))
    inter = a&b
    ll = len(inter)
    if ll:
        item = 0
        for i in inter:
            item = i
            break
        print('YES')
        print(1,item)
    else:
        print('NO')
    
