from typing import Tuple


def get_five_km_index(ref: str) -> Tuple[int, int]:
    """Calculate row and column index of 5km grid reference for 5km grid matrix.

    Args:
        ref (str): 5KM grid reference.

    Returns:
        Tuple[int, int]: row, column index of 5km grid reference matrix.
    """
    "Convert 5km grid reference to row and column"
    first_letter_offset = ord(ref[0]) - ord("A")
    # no I in matrix
    if first_letter_offset > (ord("I") - ord("A")):
        first_letter_offset -= 1
    second_letter_offset = ord(ref[1]) - ord("A")
    # no I in matrix
    if second_letter_offset > (ord("I") - ord("A")):
        second_letter_offset -= 1

    row = (
        (first_letter_offset // 5) * 100  # first letter index
        + (second_letter_offset // 5) * 20  # second letter index
        + (9 - int(ref[3])) * 2  # easting
        + (0 if ref[4] == "N" else 1)  # quadrant
    )
    col = (
        (first_letter_offset % 5) * 100  # first letter index
        + (second_letter_offset % 5) * 20  # second letter index
        + int(ref[2]) * 2  # northing
        + (0 if ref[5] == "W" else 1)  # quadrant
    )
    return row, col