import json

student_answer = """{{ STUDENT_ANSWER | e('py') }}"""
SEPARATOR = "#<ab@17943918#@>#"

error_count = 0
def error(s):
    global error_count
    print(s)
    error_count += 1

try:
    graph_rep = json.loads(student_answer)
    node_id_to_name_map = {}
    for i, node in enumerate(graph_rep['nodes']):
        node_id_to_name_map[i] = node[0] if node[0] != '' else ('#' + str(i))
    #print("Nodes:", nodes)
    edges = graph_rep['edges']
    #print("Edges:", edges)
    graph = {}
    for node_id, node_name in sorted(node_id_to_name_map.items()):
        edges = []
        for id0, id1, edge_label in graph_rep['edges']:
            if id0 == node_id:
                edges.append((node_id_to_name_map[id1], edge_label))
        edges.sort()
        graph[node_name] = edges

except json.JSONDecodeError as e:
    raise Exception("Oops. Illegal graph received (exception {}). Please report (unless you did something silly yourself)".format(e))

{% for TEST in TESTCASES %}
{{ TEST.testcode }}
{{ TEST.extra }}
{% if not loop.last %}
print(SEPARATOR)
{% endif %}
{% endfor %}