The famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.
The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to reform its system. The reform includes moving a lot of tables between rooms. Because the corridor is narrow and all the tables are big, only one table can pass through the corridor. Some plan is needed to make the moving efficient. The manager figured out the following plan: Moving a table from a room to another room can be done within 10 minutes. When moving a table from room i to room j, the part of the corridor between the front of room i and the front of room j is used. So, during each 10 minutes, several moving between two rooms not sharing the same part of the corridor will be done simultaneously. To make it clear the manager illustrated the possible cases and impossible cases of simultaneous moving.
For each room, at most one table will be either moved in or moved out. Now, the manager seeks out a method to minimize the time to move all the tables. Your job is to write a program to solve the manager's problem.
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input. Each test case begins with a line containing an integer N , 1<= N <= 200 , that represents the number of tables to move. Each of the following N lines contains two positive integers s and t, representing that a table is to move from room number s to room number t (each room number appears at most once in the N lines). From the N+3-rd line, the remaining test cases are listed in the same manner as above.
Output
The output should contain the minimum time in minutes to complete the moving, one per line.
翻译:
著名的 ACM(高级计算机制造商)公司租用了一栋楼的某一层,该楼层的形状如下图所示。
沿着走廊,楼层在北侧和南侧各有 200 个房间。最近,该公司制定了一项系统改革计划。改革内容包括在房间之间搬运大量的桌子。由于走廊很窄,而且所有的桌子都很大,所以每次只能有一张桌子通过走廊。因此需要制定一些计划来使搬运工作更高效。经理想出了如下计划:将一张桌子从一个房间搬到另一个房间可以在 10 分钟内完成。当把一张桌子从房间 i 搬到房间 j 时,会用到房间 i 前面到房间 j 前面之间的那段走廊。所以,每 10 分钟内,可以同时进行几个在不共用同一段走廊的两个房间之间的搬运工作。为了清晰说明情况,经理列举了可以同时搬运和不能同时搬运的各种情况示例。
输入包含 T 个测试用例。测试用例的数量 T 在输入的第一行给出。每个测试用例的第一行包含一个整数 N(1 <= N <= 200),它代表要搬运的桌子数量。接下来的 N 行中,每行包含两个正整数 s 和 t,表示要将一张桌子从房间编号 s 搬到房间编号 t(每个房间编号在这 N 行中最多出现一次)。从第 N + 3 行起,其余的测试用例将按照上述相同的方式列出。