We are given t test cases. For each, n, m, k (1 <= n, m <= 100, 0 <= k <= 10^4). Starting at (1,1). We can move right: cost = x (current row) to go to (x, y+1). Move down: cost = y (current column) to go to (x+1, y). We need to determine if there exists a path from (1,1) to (n,m) with total cost exactly k.
Observation: The cost of moving depends on current coordinates. Let's try to derive formula for total cost of any path. Since we can only move right and down, any path from (1,1) to (n,m) consists of exactly (n-1) down moves and (m-1) right moves, in some order.
Let's think about total cost. Suppose we have a sequence of moves. Let the moves be in order. When we move right at a point (x,y), cost = x. When we move down at a point (x,y), cost = y.
We want to compute sum_{right moves} x_i + sum_{down moves} y_j, where (x_i, y_i) are the coordinates before each right move, and (x_j, y_j) are the coordinates before each down move.
We can also think about contributions of each coordinate to total cost. The cost of right moves is sum of row indices at which we move right. Similarly, cost of down moves is sum of column indices at which we move down.
Alternatively, we can compute total cost via another method: think of each cell's contribution based on how many times we move out of it to the right or down. But maybe we can derive that all paths have the same cost? Let's test small: n=2, m=2. Path1: Right then Down: start (1,1) -> Right: cost = x=1, now at (1,2). Then Down: cost = y=2, total=3. Path2: Down then Right: from (1,1) -> Down: cost = y=1, now at (2,1). Then Right: cost = x=2, total=3. Both same. For n=2,m=3? Let's compute all paths from (1,1) to (2,3). Paths: R,R,D; R,D,R; D,R,R. Compute:
R,R,D: (1,1)->R cost1: x=1 ->(1,2) ->R cost: x=1 ->(1,3) ->D cost: y=3 => total = 1+1+3=5.
R,D,R: (1,1)->R cost1:1 ->(1,2) ->D cost: y=2 ->(2,2) ->R cost: x=2 -> total=1+2+2=5.
D,R,R: (1,1)->D cost: y=1 ->(2,1) ->R cost: x=2 ->(2,2) ->R cost: x=2? Wait careful: At (2,1) after down, then right: cost = x=2? Actually moving right from (2,1) cost = x =2, to (2,2). Then right from (2,2) cost = x=2, to (2,3). total = 1+2+2=5. So all 5. It seems all paths have same total cost. Let's test n=3,m=3: Possibly cost? Let's try path: R,R,D,D: (1,1)->R(1) ->(1,2)->R(1) ->(1,3)->D(y=3) ->(2,3)->D(y=3?) Wait down from (2,3) cost = y=3? Actually down cost is y of current cell, so from (2,3) down cost=3 ->(3,3). total =1+1+3+3=8. Another: D,D,R,R: (1,1)->D(1) ->(2,1)->D(1?) Wait down from (2,1) cost = y=1? because y=1, yes ->(3,1) ->R cost x=3 ->(3,2) ->R cost x=3 ->(3,3). total =1+1+3+3=8. Mixed: R,D,R,D: (1,1)->R(1) ->(1,2)->D(y=2) ->(2,2)->R(x=2) ->(2,3)->D(y=3) ->(3,3). total=1+2+2+3=8. All 8. So indeed all paths seem to have same total cost. Let's derive formula.
Generalize: For a path from (1,1) to (n,m) with moves: (n-1) down moves and (m-1) right moves. The total cost = sum_{down moves} y_before + sum_{right moves} x_before.
Consider the contributions: For each cell (i,j), consider how many times a move originates from it. Each right move from (i,j) contributes i, each down move from (i,j) contributes j.
Now note that any path will cross exactly one edge between cells. Another viewpoint: The sum of row indices of right moves + sum of column indices of down moves.
We can compute this sum differently: For each right move, you increase column index. For each down move, you increase row index.
We could try to compute the total cost as: The sum over all steps of something like coordinate before move.
Consider that after completing the path, you will have visited certain cells. Could we derive that total cost = sum_{i=1}^{n-1} i * something? Actually we can think of how many right moves happen at each row i. In any path, you will move right exactly (m-1) times, and these right moves must occur at various rows. Specifically, for each row i, the number of right moves taken in that row is either 0 or 1? Actually you can move right multiple times in the same row if you go across columns. Since you start at row 1, you may move right in row 1 as many times as you stay in that row before moving down. But you will eventually move down to other rows. In total, you must move right exactly (m-1) times. These right moves can be distributed among the rows you pass through. Similarly, down moves (n-1) can be distributed among columns.
Let's denote that you will travel through each row i from i=1 to n. In row i, you will enter at some column and exit at some column, and you may make several right moves within that row before moving down to next row. Actually path is monotonic: you only go right and down. So you will visit rows in increasing order. In row i, you will be at some column from some entry column to exit column, and you may move right some number of times. In particular, the number of right moves made in row i is the difference between the column you exit row i (i.e., the column when you leave row i by moving down) and the column you enter row i (when you first come into that row). But you may also move down from the same column you entered, so you might make 0 right moves. So the number of right moves in row i can range from 0 to something.
Similarly, the number of down moves in column j is the difference between row exit and entry.
Perhaps there is a simpler invariant: The total cost of a path is independent of the order and equals (n-1)(m-1) something? Let's compute for n=2,m=2: cost=3 = (22 - 1?) Actually 2+1=3? For n=2,m=3: cost=5. n=3,m=3: cost=8. n=1,m=4: cost = from (1,1) to (1,4): only right moves: three right moves, each cost x=1 (since row=1 always). So total = 3 = (1-1)something? Actually (1-1)? Let's compute. So maybe cost = (n-1)m? For n=2,m=3: (1)3=3 not 5. Or n (m-1): 22=4 not 5. Or nm - 1: 23-1=5, yes. For n=2,m=2: 22-1=3, yes. For n=3,m=3: 33-1=8, yes. For n=1,m=4: 14-1=3, yes. For n=1,m=1: 11-1=0, yes. For n=2,m=1: from (1,1) to (2,1): only down moves: cost = y=1 for down from (1,1) -> total=1, while nm-1=21-1=1, yes. For n=5,m=7: predicted cost = 5*7-1=34? Let's test with a random path: R,R,R,R,R,R,D,D,D,D? Actually from (1,1) to (5,7) need 6 rights, 4 downs. Compute along a path: maybe simple path: all rights then all downs: rights: 6 rights at row 1 each cost 1 => 6; then downs: from (1,7) down to (2,7) cost y=7, (2,7) down to (3,7) cost 7, (3,7) down to (4,7) cost 7, (4,7) down to (5,7) cost 7 => total 6+28=34 = 35-1=34. Another path: alternate: R,D,R,D,... Let's compute quickly: start (1,1)->R(1): (1,2)->D(2): (2,2)->R(2): (2,3)->D(3): (3,3)->R(3): (3,4)->D(4): (4,4)->R(4): (4,5)->D(5): (5,5)-> now need remaining rights: need to get to column 7: we are at (5,5) need 2 rights: each cost x=5 => 10, total sum: 1+2+2+3+3+4+4+5+10? Wait careful: Let's list moves: we have 6 rights, 4 downs. In this mixed path, we did: R(1), D(2), R(2), D(3), R(3), D(4), R(4), D(5), then two R(5), R(5). Sum = 1+2+2+3+3+4+4+5+5+5 = 34? Sum: 1+2=3, +2=5, +3=8, +3=11, +4=15, +4=19, +5=24, +5=29, +5=34. Yes 34.
So it seems total cost for any path from (1,1) to (n,m) is n*m - 1. Let's prove: Consider sum of costs. For each move, we add either x (if right) or y (if down). If we sum over all moves, we can also sum the contributions of all cells visited except final? Another method: Suppose we list all moves; after each move we move to a new cell. Could think of the total cost as sum over cells (except the final) of something? Actually, note that when we are at a cell (x,y), the next move will cost either x or y. If we imagine that each cell (i,j) contributes its row index to the cost if we exit via a right move, and contributes its column index if we exit via a down move. But not all cells are exited both ways; each cell (except those on the bottom or right boundary) we exit exactly once either right or down. Actually, the path visits a sequence of cells. Each cell (except the last) is exited exactly once. The exit move from a cell (i,j) costs either i (if exiting right) or j (if exiting down). So total cost = sum over visited cells except the final of cost of exit from that cell.
Now, consider the set of visited cells. The path from (1,1) to (n,m) will visit exactly (n + m - 1) cells? Actually number of cells visited in a monotonic path: you need to move (n-1)+(m-1) steps, so you visit (n+m-1) cells (including start and end). So total cost = sum_{cells visited except final} exit cost.
We can try to compute sum of exit costs in terms of coordinates of visited cells. Perhaps we can relate to sum of coordinates of all visited cells? Let's test: In the n=2,m=2 example, visited cells: (1,1), (1,2), (2,2). Exits: from (1,1) we exit right or down; from (1,2) we exit down; from (2,2) no exit. If we took path R then D: exits: (1,1) exit right cost 1; (1,2) exit down cost 2; total=3. Another path: D then R: exits: (1,1) exit down cost 1; (2,1) exit right cost 2; total=3. So sum of exit costs = 1+2=3. Sum of all visited cells (including start and end) coordinates? (1+1)+(1+2)+(2+2)=2+3+4=9, not 3.
Alternate approach: Compute total cost as (n-1)*m + (m-1)*1? No.
Better to derive a direct formula: For any path, the total cost = sum_{i=1}^{n} i * (number of right moves performed in row i) + sum_{j=1}^{m} j * (number of down moves performed in column j). But note that the number of right moves in row i equals how many columns you traverse in row i minus 1? Actually if you are in row i, you enter at some column c_in and exit at some column c_out (when you go down), you will have (c_out - c_in) right moves in that row. And you will definitely go down once from row i (unless i=n, but you don't exit row n). For rows 1..n-1, you make exactly one down move from that row (you leave each row exactly once, except the last row). So in row i (i from 1 to n-1), you have exactly one down move? Actually you can also move down multiple times? Since you only increase row, you will leave each row i at some point and never return. So for each row i < n, you will make exactly one down move from that row (the move that takes you to row i+1). For row n, you never move down. So for rows 1..n-1, there is exactly one down move from that row. However, that down move occurs at some column, say column c_i (the column when you leave row i). The cost of that down move is y = c_i. So sum of down move costs = sum_{i=1}^{n-1} c_i, where c_i is the column in which you leave row i.
Similarly, for columns j from 1 to m-1, there is exactly one right move from that column? Let's think: You move right to increase column. In each column j < m, you will make exactly one right move from that column? Actually you can be in a column multiple times across different rows? But you only move right from a column when you are at some row and move right. Since you only increase column, you will leave each column j exactly once (by a right move) when you are at some row? But careful: You can be in column j at multiple rows; however, to increase column from j to j+1, you must perform a right move. Since column number never decreases, the first time you go from column j to j+1, that's a right move. After that, you might later be in column j again? Actually once you have moved to column j+1, you cannot go back to column j because you can't move left. So you can be in column j only before you first move to column j+1. So you will be in column j in various rows as you move down, but you never return to column j after moving to j+1. So indeed, for each column j (1 <= j <= m-1), there is exactly one right move that takes you from column j to j+1. That right move occurs at some row, say r_j. The cost of that right move is x = r_j. So sum of right move costs = sum_{j=1}^{m-1} r_j.
Thus total cost = sum_{i=1}^{n-1} c_i + sum_{j=1}^{m-1} r_j, where c_i is the column where we leave row i (down move column), and r_j is the row where we leave column j (right move row). Note that the set of down moves happen at columns c_i, i=1..n-1, and the set of right moves happen at rows r_j, j=1..m-1. Also, note that the path's structure implies that these sequences are interleaved. In particular, as we traverse, the exit points (i, c_i) for rows i and (r_j, j) for columns j must be consistent with a monotone path.
In fact, the sequence of c_i (columns where we go down) is non-decreasing? As i increases, the column where we go down can increase or stay the same? Actually, consider that we move right and down; the path cannot go left or up. So if we are at row i, we go down at column c_i. Then we are at row i+1, column c_i (since down doesn't change column). Then we may move right some number of times before possibly going down again. So the column where we go down at row i+1 must be >= c_i, because we cannot move left. So c_i is a non-decreasing sequence with i from 1 to n-1. Moreover, c_{n-1} is the column where we go down from row n-1 to row n; after that we may still need to move right to reach column m, but those are right moves from row n. So final column after last down is c_{n-1}, then we do right moves in row n to reach m. So c_{n-1} <= m.
Similarly, for r_j (the row where we go right from column j to j+1), these are non-decreasing as j increases? Let's see: when we go right from column j at row r_j, we then are at column j+1, row r_j. Then we may go down before the next right move. So the next right move from column j+1 occurs at row r_{j+1} which must be >= r_j because we can't go up. So r_j is non-decreasing with j, and r_{m-1} <= n.
Additionally, the sequences satisfy a relationship: The set of down moves and right moves essentially define the path. In fact, the path is determined by the set of points where we switch direction. There is a known combinatorial representation: any monotonic path corresponds to a sequence of steps, or to a choice of which steps are down. However, the total cost formula sum_{i=1}^{n-1} c_i + sum_{j=1}^{m-1} r_j must be constant? Let's test with examples. For n=2,m=3, we have n-1=1 down move at some column c_1, and m-1=2 right moves at rows r_1, r_2. Path possibilities:
- If we do R,R,D: then down move occurs at row 1, column 3? Actually we go right twice at row 1, then down from (1,3) to (2,3). So c_1 = 3. Right moves: first right from column 1 at row 1 (r_1=1), second right from column 2 at row 1 (r_2=1). So sum = c_1 + r_1 + r_2 = 3+1+1=5.
- If we do R,D,R: then down occurs after first right: from (1,2) down to (2,2) => c_1=2. Right moves: first right from column 1 at row1 (r_1=1); second right from column 2 at row2 (r_2=2). Sum = 2+1+2=5.
- If we do D,R,R: down from (1,1) to (2,1) => c_1=1; right moves: first right from column1 at row2 (r_1=2); second right from column2 at row2 (r_2=2). Sum =1+2+2=5.
So sum =5 always.
So sum_{i} c_i + sum_{j} r_j appears constant. Could it be equal to something like (n-1)*(m-1)+ (n-1)*1 + (m-1)*1? Not exactly.
Let's compute for general n,m: Is total cost always nm - 1? Let's test with n=3,m=2. Paths from (1,1) to (3,2): need 2 down, 1 right. All paths cost? Compute: D,D,R: down from (1,1) cost y=1, down from (2,1) cost y=1? Wait down from (2,1) cost y=1 (since column=1), total down costs 2; then right from (3,1) cost x=3; total=5. D,R,D: down (1,1) cost1, then right from (2,1) cost x=2, then down from (2,2) cost y=2; total=1+2+2=5. R,D,D: right (1,1) cost1, down from (1,2) cost2, down from (2,2) cost2; total=1+2+2=5. So yes 5 = 32-1=5. Good.
So it seems total cost is always n*m - 1.
But wait, test case example: n=2,m=2, k=2 output NO, k=3 output YES. So consistent with n*m - 1 = 3. For n=2,m=2,k=4 output NO. So it's consistent.
But is it always exactly n*m - 1? Let's prove formally.
We can derive: Total cost = sum over steps. Consider all moves. There are (n-1)+(m-1) steps.
Alternatively, think of the sum of all x coordinates of cells from which we move right plus sum of all y coordinates of cells from which we move down.
Now, consider that for any path, the multiset of row indices for right moves together with column indices for down moves forms a certain set. Another way: In the grid, each cell (i,j) may be "used" as a starting point for a right move or down move, but only once.
We can also think of the total cost as: At each step, you add the coordinate that does not change. For a right move, you add x, which is the row, stays same. For a down move, you add y, which is the column, stays same.
Now, consider the sum over all steps of (x+y) before the move? Not helpful.
Perhaps we can use induction: For grid 1x1, cost 0 = 1*1-1. Assume for any (n,m) the cost is constant. Consider adding a row or column? But better: Show that the total cost for any path equals the sum of all cells' row indices? Let's attempt: For a path from (1,1) to (n,m), the set of visited cells includes all cells? No, only one path.
Another approach: Write cost as sum_{i=1}^{n-1} (the column at which you go down from row i) + sum_{j=1}^{m-1} (the row at which you go right from column j). Now, note that the pairs (i, c_i) for i=1..n-1 and (r_j, j) for j=1..m-1 together with the start and end define the path. These two sequences are complementary: because the path visits exactly those cells that are either a down point or a right point? Actually, the path goes through certain lattice points. The set of "turn" points can be considered. But we can show that sum_{i} c_i + sum_{j} r_j = n*m - 1. Let's attempt to prove.
Consider an n by m grid of cells. Actually, consider the total sum of all coordinates (i+j) over all cells? Not directly.
Alternatively, think of a "cost accumulation" as we move. Each time we move right, we pay the row number; each time we move down, we pay the column number. Now, consider the following: Starting from (1,1) to (n,m). The total cost might be expressed as sum over all cells (i,j) of something like: each cell contributes 1 if we pass through it in a certain way.
Maybe we can derive that total cost = (n-1)m + (m-1)? Let's compute: For a path that goes all rights first then all downs, cost = (m-1)*1 (since all rights at row 1) + (n-1)*m (since each down at column m costs m) = (m-1) + (n-1)*m = (n-1)m + m - 1 = nm - 1. Yes.
For a path that goes all downs first then all rights, cost = (n-1)1 (since all downs at column 1) + (m-1)n (since all rights at row n) = (n-1) + n(m-1) = nm - 1. So both extremes give n*m -1. And we have shown for mixed it also gives same. So likely constant.
Now, prove that any path gives same total cost. One can use an invariant: The sum of costs of moves along a path is independent of order. This can be shown by swapping adjacent moves. Suppose we have a segment of two moves: Right then Down vs Down then Right. In the first case, from (x,y): R cost x to (x,y+1); then D cost y+1 to (x+1,y+1). Total = x + (y+1). In the second case: D cost y to (x+1,y); then R cost x+1 to (x+1,y+1). Total = y + (x+1) = x + y + 1. So both give same sum. So any two paths that differ by swapping adjacent steps have equal total cost. Since any path can be transformed into any other by a series of adjacent swaps (like bubble sort), all paths have equal cost. This is a standard argument for such grid cost problems: if the cost of R then D equals cost of D then R, then all paths from (1,1) to (n,m) have same total cost. Because the path can be represented as a sequence of R and D, and any permutation can be achieved by swapping adjacent R and D, which does not change total cost because the local cost equality holds. However careful: The equality for swapping adjacent steps was shown from any starting cell (x,y). But note that the equality x + (y+1) = y + (x+1) holds for all x,y. So indeed swapping a R followed by D with D followed by R does not change total cost for that segment. Therefore, by performing adjacent swaps, we can convert any sequence of (n-1) D's and (m-1) R's to any other without changing total cost. Hence all paths have same total cost.
Thus, the unique total cost is some value. We computed via extreme paths: it is n*m - 1.
Let's verify: For n=1,m=4, all rights: cost = (m-1)1 = 3 = 14 -1 =3, correct. For n=4,m=1, all downs: cost = (n-1)1 =3 =41-1=3, correct.
Thus answer: YES iff k == nm - 1? But wait, check constraints: n,m up to 100, k up to 10000. nm could be up to 10000 as well (since n,m <= 100, n*m <= 10000). So k can be exactly up to 10^4. So comparison is fine.
But is it always nm - 1? Let's double-check with sample: test case 2: n=2,m=2,k=2 => 22-1=3, not 2, output NO, correct. Test case 3: k=3 => YES, correct. Test case 4: k=4 => NO. Test case 5: n=1,m=4,k=3 => 14-1=3 => YES. Test case 6: n=100,m=100,k=10000 => 100100-1=9999, not 10000 => NO. Sample says NO, correct.
Thus answer seems simple: YES if k == nm - 1, else NO. But wait, is there any nuance? What about starting at (1,1) and already at destination? That is n=m=1, then nm-1 = 0, matches. So it's consistent.
But wait: Could there be any path that spends exactly k, maybe more than one path but all same cost, so it's simply equality.
Thus for each test case, output YES if k == n * m - 1, else NO.
But is there any possibility that the total cost is something else? Let's re-express: Starting at (1,1), move right cost x (row), move down cost y (col). I derived that swapping adjacent moves preserves total cost. Let's verify with a concrete path: Starting at (1,1). Suppose we have two steps: first down then right: down cost y=1, right cost x=2 (since after down we are at (2,1), x=2). Total = 3. If we swap to right then down: right cost x=1, down cost y=2 (since after right at (1,2) y=2). Total = 3. Yes equal. So the local transformation is cost-invariant.
But does this guarantee global invariance? Usually, any sequence of R and D can be transformed to any other by adjacent swaps (like bubble sort). Since each swap preserves total cost, all sequences have same total cost. So indeed invariant.
Edge cases: Might there be any path that doesn't go exactly n-1 downs and m-1 rights? That's the only allowed moves to reach (n,m) from (1,1) with right and down only. So yes.
Thus answer is trivial.
But wait: Check the note for test case 2,3,4: They said both paths cost 1+2=3. So correct.
Thus solution: For each test case, compute n*m - 1, compare to k, print YES if equal else NO.
But maybe there is a catch: Input constraints say k can be 0 and n,m >=1. For n=1,m=1,k=0, it's YES. So fine.
Double-check with some random numbers: n=3,m=5, predicted cost = 15-1=14. Compute extremes: all rights then downs: (5-1)*1 =4, then (3-1)*5=10, total=14. All downs then rights: (3-1)*1=2, then (5-1)*3=12, total=14. Mixed: say R,R,D,R,D,R,D? Let's compute quickly: (1,1) -> R(1)=1 to (1,2) -> R(1)=1 to (1,3) -> D(y=3)=3 to (2,3) -> R(x=2)=2 to (2,4) -> D(y=4)=4 to (3,4) -> R(x=3)=3 to (3,5). Total 1+1+3+2+4+3=14. Yes.
Thus answer stands.
But wait: Problem statement says "0 ≤ k ≤ 10^4". n,m up to 100 so nm max 10,000, so k could be up to 10,000. nm -1 max 9999. So if k = 10000, answer always NO. That's fine.
Therefore, the solution is extremely simple.
We need to output for each test case.
Thus implementation: read t, loop, read n,m,k, if k == n*m - 1 print "YES", else "NO".
But before finalizing, I want to check if there might be any twist: The cost definitions: moving right costs x burles (current row), moving down costs y burles (current column). Indeed.
But one might think about if there are any alternative paths that could skip some moves? No.
Thus answer is correct.
But let's consider if the grid indices start at 1,1. Yes.
Now, we must output YES/NO in any case.
Thus final answer: for each test case, condition is k == n * m - 1.
But wait, there's another possibility: Maybe you can also stay? No, only moves.
Thus solution complete.
But there is a nuance: The reasoning about swap invariance might require that the costs only depend on current position. However, when swapping adjacent moves, the starting point is same but the intermediate positions differ. But we showed that for a segment starting from a given (x,y), the cost of "RD" is x + (y+1) and "DR" is y + (x+1), which are equal. So if we have a longer sequence, swapping adjacent R and D will not affect the total cost because the rest of the sequence after that segment will have the same starting position after the two moves (both lead to (x+1,y+1)). So swapping two adjacent steps does not change overall cost. So indeed all sequences have same total cost.
Thus problem solved.
Time complexity O(t).
Now, let's produce final answer.
However, be careful: The input example has 6 test cases, we must output accordingly.
Edge test: n=100,m=100,k=9999 -> YES.
Thus final.
But let's double-check with some other values: n=1,m=100,k=99 => 1*100-1=99 => YES.
n=100,m=1,k=99 => 100*1-1=99 => YES.
So fine.
Thus answer.
But wait, let's think if there is any scenario where you can overshoot? No.
Thus solution.
Now, I will produce the final answer.
But perhaps the problem expects us to notice the invariant and answer accordingly.
Alright.
Now, I'll write the explanation in final.
Let me produce final output with code snippet.
But the user asks for: "There is a n × m grid. ... Can you reach cell (n, m) spending exactly k burles?" So we respond with answer.
Given we have to output "YES" or "NO". So code will do that.
Potential pitfalls: integer overflow not an issue since n,m <=100 => n*m <=10000, fits in int.
So final answer.
Now, produce final response. The total cost of any path from (1,1) to (n,m) is always the same.
This can be seen by observing that swapping a right-then-down pair with a down-then-right pair does not change the total cost: from any cell (x,y), the sequence "right then down" costs x + (y+1), while "down then right" costs y + (x+1). Both are equal. Since any path can be transformed into any other by such swaps, all paths have identical total cost.
A convenient path (all rights then all downs) gives a total of (m-1)·1 + (n-1)·m = n·m – 1. Another extreme (all downs then all rights) gives (n-1)·1 + (m-1)·n = n·m – 1. Hence the unique possible cost is n·m – 1.
Therefore, the answer is YES if and only if k equals n·m – 1, otherwise NO.
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
if (k == n * m - 1)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}