Mr. Panda and Dominoes
题号:NC202138
时间限制:C/C++/Rust/Pascal 12秒,其他语言24秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Mr. Panda likes creating and solving mathematical puzzles. One day, Mr. Panda came up with a puzzle when he was playing dominoes.In a grid that consists of an infinite number of rows and columns, all cells are white except given cells which are colored black. Mr. Panda wants to know how many dominoes there are in the gird.A domino is a rectangle that meets the following requirements.
  • The domino is formed of a continuous subset of the rows and columns of the grid.
  • The domino has at least row and column.
  • The cells on the edge of the domino are black. It means the topmost row, the bottommost row, the leftmost column and the rightmost column only consist of black cells.
  • The aspect ratio of the domino is or . It means, if the domino has columns, it should have either rows or rows ( is an even number in this case).
For example, in the chart below, the grid on the left contains dominos ( dominos of and dominos of ), and the grid on the right contains dominos ( dominos of , 4 dominos of and a domino of ).

Because the grid is huge, Mr. Panda is too lazy to count the number of dominoes. Could you please help Mr. Panda find how many dominoes there are in the gird?

输入描述:

The first line of input gives the number of test cases, .  test cases follow.
Each test case starts with a line consists of an integer - , the number of black cells in the gird.
Then, lines follow. Each line consists of integers and , indicating row and column of a black cell in the grid.



over all test cases
For each test, no two black cells are in the same position

输出描述:

For each test case, output one line containing ``Case #x: y'', where x is the test case number (starting from 1) and y is the number of dominos that Mr. Panda wants to know for the i-th input data set.
示例1

输入

复制
2
7
1 1
1 2
1 3
2 2
3 1
3 2
3 3
14
1 1
1 2
1 3
1 4
1 5
1 6
2 1
2 6
3 1
3 2
3 3
3 4
3 5
3 6

输出

复制
Case #1: 6
Case #2: 15