for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    broken = 0
    for item in a:
        if item in b:
            print('YES')
            print(1, item)
            broken = 1
            break
    if not broken:
        print('NO')
