#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9) + 7;
const long long inf = 1e17;
const int N = 100005;
int t;
int dp[55][55][55];
int solve(int x, int y, int k) {
  if (x * y == k or !k) return 0;
  if (x * y < k) return MOD;
  if (dp[x][y][k] != -1) return dp[x][y][k];
  int ans = MOD;
  for (int i = 1; i <= x - i; i++) {
    for (int j = 0; j <= k; j++) {
      ans = min(ans, y * y + solve(i, y, j) + solve(x - i, y, k - j));
    }
  }
  for (int i = 1; i <= y - i; i++) {
    for (int j = 0; j <= k; j++) {
      ans = min(ans, x * x + solve(x, i, j) + solve(x, y - i, k - j));
    }
  }
  dp[x][y][k] = ans;
  return ans;
}
int main() {
  cin >> t;
  memset(dp, -1, sizeof dp);
  while (t--) {
    int a, b, c;
    scanf("%d", &a), scanf("%d", &b), scanf("%d", &c);
    cout << solve(a, b, c) << endl;
  }
  return 0;
}
