for t in range(int(input())):
    n, m = map(int, input().split())
    a = set(map(int, input().split()))
    b = set(map(int, input().split()))
    c = a & b
    if len(c) == 0:
        print('NO')
    else:
        print('YES')
        for x in c:
            print('1', x)
            break
