for i in range(int(input())):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    f= 0
    for s in a:
        if s in b:
            f=1
            break
    if f==0:
        print('NO')
    else:
        print('YES')
        print(f'1 {s}')