def _needleman_wunsch_backward_pass(n_x, n_y, s, f, gap_score):
    """
    Compute the backward pass of the Needleman Wunsch algorithm.

    Args:
        n_x, n_y (int): The lengths of the sequences to be aligned.
        s (array): Match/mismatch similarity matrix.
        f (array): Forward pass alignment matrix.
        gap_score (numeric): Score for a insertion/deletion.

    Returns:
        alignment (list of tuples): The aligned sequence, as a list of pairs of indices.
    """
    alignment = []
    i = n_x
    j = n_y
    while i > 0 or j > 0:
        if i > 0 and j > 0 and f[i][j] == f[i - 1][j - 1] + s[i - 1][j - 1]:
            alignment.append((i - 1, j - 1))
            i = i - 1
            j = j - 1
        elif i > 0 and f[i][j] == f[i - 1][j] + gap_score:
            alignment.append((i - 1, None))
            i = i - 1
        else:
            alignment.append((None, j - 1))
            j = j - 1
    alignment = alignment[::-1]
    return alignment
