for t in range(int(input())):
    m,n=map(int, input().split())

    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    dic=dict()
    for xx in x:
        dic[xx]=0
    f=False
    for yy in y:
        if yy in dic:
            f=True
            print("YES")
            print(1, yy)
            break
    if not f:
        print("NO")