PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000011. Bạn bè trên mạng (Virtual Friends)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bạn bè trên mạng (Virtual Friends)

Virtual Friends

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Initially, there are no friendships. Whenever two people become friends, they belong to the same social network. People are also in the same network if they are connected through a chain of friendships. After each new friendship, report the size of the network containing the two people involved.

Input

The first line contains an integer ff, the number of new friendships. Each of the next ff lines contains the names of two people. Names contain no spaces and are case-sensitive.

Output

After each friendship, print the size of the network containing the two people, one answer per line.

Subtasks

  • Subtask 1 (20 points): 1≤f≤601\le f\le 60; each name consists of 11 to 2020 English letters (A–Z, a–z).
  • Subtask 2 (30 points): 1≤f≤40001\le f\le 4000; each name consists of 11 to 2020 English letters (A–Z, a–z).
  • Subtask 3 (50 points): 1≤f≤1000001\le f\le 100000; each name consists of 11 to 2020 English letters (A–Z, a–z).

Examples

Input

3
Fred Barney
Barney Betty
Betty Wilma

Output

2
3
4

Explanation

Fred and Barney form a group of 2, Betty joins it to make 3, and Wilma joins to make 4.