for t in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    vis = [0 for i in range(1001)]
    for i in a:
        vis[i] = 1
    flg = False

    for j in b:
        if vis[j]:
            flg = True
            break

    if flg:
        print('YES')
        print(1, j)
    else:
        print('NO')
