for t in range(int(input())):
    n,m = map(int,input().split())
    a = set([int(s) for s in input().split()])
    b = set([int(s) for s in input().split()])
    x = list(a & b)
    if x == []:
        print('NO')
    else:
        print('YES')
        print(1,x[0])