def dfs(v): while next_to[v] < K: u = next_to[v] next_to[v] += 1 dfs(u) path.append(u) K = 26 next_to = [0] * K path = [] dfs(0) path.reverse() def c(x): return chr(x + ord('A')) for i in range(K * K): a = path[i] b = path[(i+1) % len(path)] print(f'{c(a)}{c(b)}')