def ancestors(all_prev):
    """Given an assignment of values, construct a list of the relevant
    parents, e.g. 1, i, a, ii, A gives us 1, ii, A"""
    # Group (type, idx, depth) per marker
    all_prev = [tuple(all_prev[i:i + 3]) for i in range(0, len(all_prev), 3)]

    result = [None] * 10
    for prev_type, prev_idx, prev_depth in all_prev:
        result[prev_depth] = (prev_type, prev_idx, prev_depth)
        result[prev_depth + 1:] = [None] * (10 - prev_depth)
    return [r for r in result if r]