t = int(input())
while t:
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    ha = {}
    f = 0
    for i in range(n):
        ha[a[i]] = 1
    for i in range(m):
        if b[i] in ha:
            f = 1
            print('YES')
            print(1,end=' ')
            print(b[i])
            break
    if f == 0:
        print('NO')
    t = t - 1
