# Original solution
import sys


class UnionFind:
    def __init__(self, n):
        self._n = n
        self._parents = [-1] * n

    def find(self, x):
        if self._parents[x] < 0:
            return x
        else:
            self._parents[x] = self.find(self._parents[x])
            return self._parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x

        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def size(self, x):
        return -self._parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def roots(self):
        return [i for i, x in enumerate(self._parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def groups(self):
        g = {r: [] for r in self.roots()}
        for i in range(self._n):
            g[self.find(i)].append(i)
        return g

    def members(self, x):
        g = self.groups()
        return g[self._parents[x]]


def read():
    return sys.stdin.buffer.readline().rstrip()


def main():
    n = int(read())
    txy = [(0, 0)] * n
    xt = [0] * n
    yt = [0] * n
    for i in range(n):
        x, y = [int(i) - 1 for i in read().split()]
        txy[i] = (x, y)
        xt[x] = i
        yt[y] = i
    x = [set() for _ in range(n)]
    y = [set() for _ in range(n)]
    for xi in range(n):
        if xi == 0:
            x[xi] = {xt[xi]}
        else:
            x[xi] = x[xi - 1] | {xt[xi]}
    for yi in range(n):
        if yi == 0:
            y[yi] = {yt[yi]}
        else:
            y[yi] = y[yi - 1] | {yt[yi]}
    seen = [False] * n
    uf = UnionFind(n)
    for i in range(n):
        if seen[i]:
            continue
        xi, yi = txy[i]
        if xi * yi == 0:
            continue
        for j in x[xi - 1] & y[yi - 1]:
            uf.union(i, j)
            seen[j] = True
    for i in range(n):
        print((uf.size(i)))


if __name__ == '__main__':
    main()


# Optimized solution
import sys


class UnionFind:
    def __init__(self, n):
        self._n = n
        self._parents = [-1] * n

    def find(self, x):
        if self._parents[x] < 0:
            return x
        else:
            self._parents[x] = self.find(self._parents[x])
            return self._parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self._parents[x] > self._parents[y]:
            x, y = y, x

        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def size(self, x):
        return -self._parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def roots(self):
        return [i for i, x in enumerate(self._parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def groups(self):
        g = {r: [] for r in self.roots()}
        for i in range(self._n):
            g[self.find(i)].append(i)
        return g

    def members(self, x):
        g = self.groups()
        return g[self._parents[x]]


def read():
    return sys.stdin.buffer.readline().rstrip()


def main():
    n = int(read())
    t = [(0, 0, 0) for _ in range(n)]
    for i in range(n):
        x, y = list(map(int, read().split()))
        t[i] = (x, y, i)
    t.sort()
    uf = UnionFind(n)
    for i in range(n):
        xi, yi, ti = t[i]
        for j in range(i):
            xj, yj, tj = t[j]
            if (xi - xj) * (yi - yj) > 0:
                uf.union(ti, tj)
    for i in range(n):
        print((uf.size(i)))


if __name__ == '__main__':
    main()