Colby's Costly Collectibles

Count the unit triangles inside a simple polygon traced by axis moves on a triangular grid.

Medium6GeometryMathNo attempts yetTime limit1sMemory limit256 MB

Problem

Colby's workshop builds a large grid out of stones shaped like equilateral triangles, then cuts shapes out of that grid and sells them as jewellery. A customer picks a shape under three rules.

  1. Cuts follow the edges of the triangles.
  2. The jewel is one piece. A connection at a single vertex is too weak, so triangles are joined along edges.
  3. The jewel has no holes.

The figure above shows one jewel made this way.

The customer pays per triangle, so Colby needs to know how many triangles went into a jewel. Given the outer boundary of the jewel, compute the number of triangles. Rules 2 and 3 imply the boundary never crosses or touches itself.

Input

The first line has the number of test cases TT (1T1001 \le T \le 100). Each test case is given as follows.

  • One line with the number of cuts CC (3C1003 \le C \le 100).
  • Then CC lines giving the moves that trace the boundary of the jewel in counterclockwise order. Each line has one of the letters x, y or z for the direction, followed by an integer for the number of steps. The number of steps can be negative, which means moving along the opposite of that axis.

The three axes point as shown below.

Consecutive axes are 60 degrees apart, and the y axis points halfway between the x axis and the z axis. One step along x followed by one step along z lands on the same vertex as one step along y.

As in the figure above, starting at the lower left corner and moving one step along x, one step along z, then one step against y traces the boundary of a single triangle.

The boundary never touches itself and always returns to its starting vertex. The total length of the boundary is at most 1000. The path starts at a vertex and every segment ends at a vertex. No two consecutive segments use the same axis, and the last segment and the first segment use different axes as well.

Output

For each test case, print the number of triangles NN on its own line.