def build_scoring_matrix(alphabet, diag_score, off_diag_score, dash_score):
    """
    Takes as input a set of characters alphabet and three scores diag_score,
    off_diag_score, and dash_score. The function returns a dictionary of
    dictionaries whose entries are indexed by pairs of characters in alphabet
    plus '-'. The score for any entry indexed by one or more dashes is
    dash_score. The score for the remaining diagonal entries is diag_score.
    Finally, the score for the remaining off-diagonal entries is off_diag_score.
    """
    scoring_matrix = {'-': {'-': dash_score}}

    for letter1 in alphabet:
        if letter1 not in scoring_matrix:
            scoring_matrix[letter1] = {}
        scoring_matrix[letter1]['-'] = dash_score
        scoring_matrix['-'][letter1] = dash_score

        for letter2 in alphabet:
            if letter1 == letter2:
                scoring_matrix[letter1][letter2] = diag_score
            else:
                scoring_matrix[letter1][letter2] = off_diag_score

    return scoring_matrix