for _ in range(int(input())):
    n,m=map(int,input().split(" "))
    record=set(map(int,input().split()))
    mArr=list(map(int,input().split()))
    possible=False
    for i in mArr:
        num=len(record)
        record.add(i)
        if num==len(record):
            possible=True
            print(f'\nYES\n1 {i}',end="")
            break
        else:
            record.remove(i)
    if not possible:
        print("\nNO",end="")