import os
import math
def solution():
    t=int(input())
    while(t>0):
        n,m = map(int,input().split())
        a=set(map(int,input().split()))
        b=set(map(int,input().split()))
        for x in a:
            if x in b:
                print("YES")
                print("1",x)
                break
        else:
            print("NO")
        t-=1
if __name__ == '__main__':
    solution()