#include <bits/stdc++.h>
using namespace std;
const int N = 32;
const int inf = 1e9 + 10;
int dp[N][N][2 * N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      for (int k = 0; k < 2 * N; k++) dp[i][j][k] = inf;
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      if (i * j < 2 * N) dp[i][j][i * j] = 0;
      dp[i][j][0] = 0;
    }
  }
  for (int i = 1; i < N; i++) {
    for (int j = 1; j < N; j++) {
      for (int k = 1; k < 2 * N; k++) {
        for (int s = 1; s <= k; s++) {
          for (int t = 1; t < i; t++)
            dp[i][j][k] =
                min(dp[i][j][k], dp[t][j][s] + dp[i - t][j][k - s] + j * j);
          for (int t = 1; t < j; t++)
            dp[i][j][k] =
                min(dp[i][j][k], dp[i][t][s] + dp[i][j - t][k - s] + i * i);
        }
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int n, m, k;
    cin >> n >> m >> k;
    cout << dp[n][m][k] << '\n';
  }
  return 0;
}
