xay loves trees
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

You have two trees rooted at 1 that both have n nodes. You need to find the largest subset of such that:

1. On the first tree, the set is connected, and for any two points u, v in set, one of u or v is an ancestor of the other.
2. On the second tree, for any two points u, v in set, none of u or v is an ancestor of the other.

Output the biggest size.

输入描述:

The first line contains an integer t () — the number of testcases. The description of the testcases follows.

The first line of each testcase contains an integer n ().

Each of the next n-1 lines contains two integers u_i,v_i () — Represents an edge on the first tree.

Each of the next n-1 lines contains two integers u_i,v_i () — Represents an edge on the second tree.

It is guaranteed that the given graphs are trees.

It is guaranteed that the sum of n over all testcases doesn't exceed .

输出描述:

For each testcase print a single integer — the size of the maximum subset.
示例1

输入

复制
3
5
2 1
2 5
5 3
2 4
2 1
1 5
1 3
3 4
5
5 3
3 1
5 4
3 2
5 3
5 1
3 4
3 2
5
5 3
5 1
5 2
5 4
5 3
3 1
5 2
3 4

输出

复制
3
1
2