for t in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    for i in range(n):
        for j in range(m):
            if a[i] == b[j]:
                print('YES')
                print(1, a[i])
                break
        if a[i] == b[j]:
            break
    else:
        print('NO')
    
    
