t = int(input())

for i in range(t):
    n, m = list(map(int, input().split()))
    a = list(input().split())
    b = list(input().split())

    for k in a:
        x = []
        if k in b:
            print('YES')
            x.append(int(k))
            print(len(x), str(x).replace('[', '').replace(']', ''))
            break
    if k not in b:
        print('NO')