#include <bits/stdc++.h>
using namespace std;
int dp[33][33][55];
int f(int n, int m, int k) {
  if (dp[n][m][k] != -1) {
    return dp[n][m][k];
  }
  if (k == 0 || n * m == k) {
    return dp[n][m][k] = 0;
  }
  if (n * m < k) {
    return dp[n][m][k] = 1e9;
  }
  int cur = 1e9;
  for (int i = 1; i <= n / 2; i++) {
    for (int left = 0; left <= k; left++) {
      cur = min(cur, f(i, m, left) + f(n - i, m, k - left) + m * m);
    }
  }
  for (int i = 1; i <= m / 2; i++) {
    for (int left = 0; left <= k; left++) {
      cur = min(cur, f(n, i, left) + f(n, m - i, k - left) + n * n);
    }
  }
  return dp[n][m][k] = cur;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  memset(dp, -1, sizeof(dp));
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    cout << f(n, m, k) << '\n';
  }
  return 0;
}
