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