#include <bits/stdc++.h>
using namespace std;
const int N = 32;
const int M = 52;
const long long INF = 1e15 + 7;
long long dp[N][N][M];
int main() {
  ios::sync_with_stdio(false);
  for (int i = 1; i < N; i++)
    for (int j = 1; j < N; j++) {
      for (int k = 1; k < M; k++) dp[i][j][k] = INF;
      if (i * j < M) dp[i][j][i * j] = 0;
    }
  for (int i = 1; i < N; i++)
    for (int j = 1; j < N; j++)
      for (int k = 1; k < M; k++) {
        for (int x = 1; x < i; x++)
          for (int t = 0; t <= k; t++)
            dp[i][j][k] =
                min(dp[i][j][k], dp[x][j][t] + dp[i - x][j][k - t] + j * j);
        for (int x = 1; x < j; x++)
          for (int t = 0; t <= k; t++)
            dp[i][j][k] =
                min(dp[i][j][k], dp[i][x][t] + dp[i][j - x][k - t] + i * i);
      }
  int t;
  cin >> t;
  while (t--) {
    int r, c, k;
    cin >> r >> c >> k;
    cout << dp[r][c][k] << "\n";
  }
  return 0;
}
