import sys; input = sys.stdin.readline
def insert(words):
now = trie
for word in words:
now = now.setdefault(word, dict())
def sout(now,depth=0):
for word in sorted(now):
print("--"*depth+word)
sout(now[word], depth+1)
trie = dict()
for _ in range(int(input())):
K, *words = input().split()
insert(words)
sout(trie)
간단히 딕셔너리로 구현한 트라이 구조로 단어들을 저장하고,
depth를 저장해 재귀하며 조건에 맞게 출력하는 함수를 구현해 간단하게 출력할 수 있습니다.