for _ in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(set(a).intersection(b))
    if(c==[]):
        print("NO")
    else:
        print("YES")
        print(1,sorted(c)[0])
    