def process_state(term, valid_transitions):
    """Process a state and return next state."""
    try:
        return valid_transitions[term]
    except KeyError as error:
        raise KeyError(f"Indefinition , Invalid Transition: {error}.")