w, h, n = list(map(int, input().split()))

l = list()

for i in range(0, n):

    x, y, a = list(map(int, input().split()))

    l.append([x, y, a])



white_check = list()

for a in range(0, h):

    white_check.append([1]*w)



for i in range(0, n):

    a = l[i][2]

    height = l[i][1]

    width = l[i][0]



    if a == 1:

        for y in range(0, h):

            for x in range(0, width):

                white_check[y][x] = 0

    elif a == 2:

        for y in range(0, h):

            for x in range(width, w):

                white_check[y][x] = 0

    elif a == 3:

        for y in range(0, height):

            for x in range(0, w):

                white_check[y][x] = 0

    else:

        for y in range(height, h):

            for x in range(0, w):

                white_check[y][x] = 0



s = 0



for a in range(h):

    s += sum(white_check[a])



print(s)

W, H, N = list(map(int, input().split()))



X = Y = 0



for i in range(0, N):

    x, y, a = list(map(int, input().split()))



    if a == 1:

        X = max(X, x)

    elif a == 2:

        W = min(W, x)

    elif a == 3:

        Y = max(Y, y)

    else:

        H = min(H, y)



print((max(W-X, 0)*max(H-Y, 0)))

w, h, n = list(map(int, input().split()))
l = list()
for i in range(0, n):
    x, y, a = list(map(int, input().split()))
    l.append([x, y, a])
white_check = list()
for a in range(0, h):
    white_check.append([1] * w)
for i in range(0, n):
    a = l[i][2]
    height = l[i][1]
    width = l[i][0]
    if a == 1:
        for y in range(0, h):
            for x in range(0, width):
                white_check[y][x] = 0
    elif a == 2:
        for y in range(0, h):
            for x in range(width, w):
                white_check[y][x] = 0
    elif a == 3:
        for y in range(0, height):
            for x in range(0, w):
                white_check[y][x] = 0
    else:
        for y in range(height, h):
            for x in range(0, w):
                white_check[y][x] = 0
s = 0
for a in range(h):
    s += sum(white_check[a])
print(s)

W, H, N = list(map(int, input().split()))
X = Y = 0
for i in range(0, N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        X = max(X, x)
    elif a == 2:
        W = min(W, x)
    elif a == 3:
        Y = max(Y, y)
    else:
        H = min(H, y)
print((max(W - X, 0) * max(H - Y, 0)))

-w, h, n = list(map(int, input().split())) -l = list() -for i in range(0, n): +W, H, N = list(map(int, input().split())) +X = Y = 0 +for i in range(0, N): -    l.append([x, y, a]) -white_check = list() -for a in range(0, h): -    white_check.append([1] * w) -for i in range(0, n): -    a = l[i][2] -    height = l[i][1] -    width = l[i][0] -        for y in range(0, h): -            for x in range(0, width): -                white_check[y][x] = 0 +        X = max(X, x) -        for y in range(0, h): -            for x in range(width, w): -                white_check[y][x] = 0 +        W = min(W, x) -        for y in range(0, height): -            for x in range(0, w): -                white_check[y][x] = 0 +        Y = max(Y, y) -        for y in range(height, h): -            for x in range(0, w): -                white_check[y][x] = 0 -s = 0 -for a in range(h): -    s += sum(white_check[a]) -print(s) +        H = min(H, y) +print((max(W - X, 0) * max(H - Y, 0)))