for _ in range(int(input())):
    a, b = map(int, input().split())
    l1 = list(map(int, input().split()))
    l2 = list(map(int, input().split()))
    for e in l1:
        if e in l2:
            print("YES")
            print("1 " + str(e))
            break
    else:
        print('NO')
