def read_scoring_matrix(filename):
    """
    Helper function to read a scoring matrix from a file.
    Returns the scoring matrix as a dictionary.
    """
    matrix_file = open(filename, 'r')
    scoring_matrix = dict()
    # Read the first line and create a list
    column_values = matrix_file.readline().split()
    # Read the other lines
    for line in matrix_file.readlines():
        scores = line.split()
        row_value = scores.pop(0)
        scoring_matrix[row_value] = dict()
        for column_value, score in zip(column_values, scores):
            scoring_matrix[row_value][column_value] = int(score)
    matrix_file.close()

    return scoring_matrix