p00616 Cubes Without Holes
There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.


<image>


Then, as shown in the figure above (right), make a hole that penetrates horizontally or vertically from the marked surface to the opposite surface.

Your job is to create a program that reads the positions marked n and counts the number of small cubes with no holes.



Input

The input consists of several datasets. Each dataset is given in the following format:


n h
c1 a1 b1
c2 a2 b2
..
..
..
ch ah bh


h is an integer indicating the number of marks. The h lines that follow enter the positions of the h marks. The coordinate axes shown in the figure below will be used to specify the position of the mark. (x, y, z) = (1, 1, 1) is the lower left cube, and (x, y, z) = (n, n, n) is the upper right cube.


<image>


ci is a string indicating the plane marked with the i-th. ci is one of "xy", "xz", and "yz", indicating that the i-th mark is on the xy, xz, and yz planes, respectively.

ai and bi indicate the coordinates on the plane indicated by ci. For the xy, xz, and yz planes, ai and bi indicate the plane coordinates (x, y), (x, z), and (y, z), respectively. For example, in the above figure, the values ​​of ci, ai, and bi of marks A, B, and C are "xy 4 4", "xz 1 2", and "yz 2 3", respectively.

When both n and h are 0, it indicates the end of input.

You can assume that n ≤ 500 and h ≤ 200.

Output

For each dataset, print the number of non-perforated cubes on one line.

Example

Input

4 3
xy 4 4
xz 1 2
yz 2 3
4 5
xy 1 1
xy 3 3
xz 3 3
yz 2 1
yz 3 3
0 0


Output

52
46
```python
# AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u

import sys
from sys import stdin
input = stdin.readline

# n <= 500,  2^9 = 512
while True:
	n, h = map(int, input().split())
	if n == 0: break
	ans = []
	for i in range(h):
		c, a, b = input().split()
		a, b = int(a)-1, int(b)-1
		if c == "xy":
			ans += [a+(b<<9)+(z<<18) for z in range(n)]
		elif c == "xz":
			ans += [a+(y<<9)+(b<<18) for y in range(n)]
		else:
			ans += [x+(a<<9)+(b<<18) for x in range(n)]
	print(n**3-len(set(ans)))

```