import collections


def merge(qrels, run):
  """Merge qrels and runs into a single dict of key: topic, 
  value: tuple(relevant_doc_ids, candidate_doc_ids)"""
  data = collections.OrderedDict()
  for topic, candidate_doc_ids in run.items():
    data[topic] = (qrels[topic], candidate_doc_ids)
  return data