Square Coloring
시간 제한1초메모리 제한1024 MB
가로, 세로, 그리고 최대 다섯 개의 대각선 선분 색칠 연산을 수행한 뒤 n x m 판에서 검은 칸의 수를 센다.
문제
There is an by chessboard with squares in total. Rows and columns are numbered starting from , and the coordinates of the square in the -th column and -th row are denoted as . Initially, all squares are white. Now, you need to perform coloring operations on this chessboard.
There are three types of coloring operations:
- Color a horizontal line black. Specifically, given two squares and with , color all squares between (including) these two squares black.
- Color a vertical line black. Specifically, given two squares and with , color all squares between (including) these two squares black.
- Color a diagonal line black. Specifically, given two squares and with and , color all squares with coordinates on the diagonal between these two squares, where . The number of times this type of coloring operation occurs is no more than .
Now you want to know how many black squares there are on the chessboard after performing coloring operations.
입력
The first line of input contains an integer , which represents the test case number. If , it means that this test case is a sample test.
The second line of input contains three positive integers , , and , which respectively represent the number of columns, rows, and the number of coloring operations on the chessboard.
Then lines follow, each line containing five positive integers . Among them, represents the first type of coloring operation, represents the second type of coloring operation, and represents the third type of coloring operation. represent the four parameters of the coloring operation.
출력
Output a line containing an integer, representing the number of black squares on the chessboard that have been colored.
제한
For all test data, it is guaranteed that: , and there are at most operations of the third type.