import sys
from collections import deque, defaultdict


def bfs(graph, start, visited):
    queue = deque([(start, 0)])
    visited.add(start)
    max_depth = 0

    while queue:
        node, depth = queue.popleft()
        max_depth = max(max_depth, depth)

        for neighbor in graph[node]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append((neighbor, depth + 1))

    return max_depth


# Read the input from stdin
def read_input():
    input = sys.stdin.read().splitlines()
    idx = 0
    graphs = []

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

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

        graphs.append(graph)

    return graphs


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

    for node in graph:
        if node not in visited:
            height = bfs(graph, node, visited)
            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)))