# 1. 마지막 단어의 마지막 글자가 다음 첫글자인지
# 2. 이전에 사용한 단어인지 -> dict로 최적화
def solution(n, words):
    answer = [0, 0]
    check = {}
    temp = words[0]
    check[temp] = 1
    for i in range(1, len(words)) :
        word = words[i]
        if temp[-1] == word[0] and word not in check :
            check[word] = 1
            temp = word
        else :
            answer = [i%n+1, i//n+1]
            break

    return answer