def _ReorderMapByTypTags(result_map):
  """Rearranges|result_map| to use typ tags as the top level keys.

  Args:
    result_map: Aggregated query results from results.AggregateResults

  Returns:
    A dict containing the same contents as |result_map|, but in the following
    format:
    {
      typ_tags (tuple of str): {
        suite (str): {
          test (str): build_url_list (list of str),
        },
      },
    }
  """
  reordered_map = {}
  for suite, test_map in result_map.items():
    for test, tag_map in test_map.items():
      for typ_tags, build_url_list in tag_map.items():
        reordered_map.setdefault(typ_tags,
                                 {}).setdefault(suite,
                                                {})[test] = build_url_list
  return reordered_map