def dfs(reactions, chemical, seen):
    """DFS to traverse all reaction requirements for chemical."""
    seen.add(chemical)
    if chemical == 'ORE':
        return []
    order = []
    _, needed_chemicals = reactions[chemical]
    for next_chemical, _ in needed_chemicals.items():
        if next_chemical not in seen:
            order.extend(dfs(reactions, next_chemical, seen))
    return order + [chemical]