import sys
from collections import defaultdict


def dfs(graph, node, visited, depth):
    visited.add(node)
    max_depth = depth

    for neighbor in graph[node]:
        if neighbor not in visited:
            max_depth = max(max_depth, dfs(graph, neighbor, visited, depth + 1))

    return max_depth

def process_graph(graph):
    visited = set()
    heights = []

    for node in graph:
        if node not in visited:
            height = dfs(graph, node, visited, 0)
            heights.append(height)

    return heights

input = sys.stdin.read().splitlines()
index = 0
graphs = []

while index < len(input):
    n = int(input[index])
    index += 1
    graph = defaultdict(list)

    for i in range(n):
        line = list(map(int, input[index].split()))
        graph[i] = line
        index += 1

    graphs.append(graph)

results = []
for graph in graphs:
    heights = process_graph(graph)
    results.append(heights)

for heights in results:
    print(" ".join(map(str, heights)))
