Rotating Tetris Pieces

Background

   A tetris piece is a two-dimensional figure made up from unit squares. Valid tetris pieces are constructed by stacking squares together to the left, right, bottom or top of each other. Figure 1 shows three tetris pieces made up from 4 squares.


Figure 1 - Different pieces made with 4 squares.

   Given a tetris piece we consider the ones obtained by rotating it on the plane by 0, 90, 180, 270 degrees. Some pieces generate four different figures by these rotations (cf. figure 1 right), whereas in others we get repeated figures (cf. figure 1 left and center).

Problem

   Write a program that reads as input the coordinates of the squares making up a piece and outputs the number of different pieces obtained by rotations.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

   The input is a sequence of (x,y) coordinate pairs; the values for x and y are non-negative integers and separated by a ',' (a comma); coordinate pairs are separated by white-spaces and the order among pairs is non-relevant. The end of the list is marked by a '-1,-1'.

   Example: for the piece on the right, the input data could be: 0,1  0,2  1,1  2,1  2,0  -1,-1

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

   The output should be the number of different pieces obtained by rotations (between 1 and 4). For the input above the output should be 2.

Sample Input
1

0,1  0,2  1,1  2,1  2,0  -1,-1

Sample Output
2