#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
int dp[31][31][51];
int solve(int n, int m, int k) {
  if (n * m < k) return OO;
  if (n * m == k or !k) return 0;
  if (dp[n][m][k] != -1) return dp[n][m][k];
  int ans = OO;
  for (int i = 1; i < n; i++) {
    ans = min(ans, solve(i, m, k) + m * m);
    ans = min(ans, solve(n - i, m, k) + m * m);
    for (int j = 1; j < k; j++)
      ans = min(ans, solve(i, m, j) + solve(n - i, m, k - j) + m * m);
  }
  for (int i = 1; i < m; i++) {
    ans = min(ans, solve(n, i, k) + n * n);
    ans = min(ans, solve(n, m - i, k) + n * n);
    for (int j = 1; j < k; j++)
      ans = min(ans, solve(n, i, j) + solve(n, m - i, k - j) + n * n);
  }
  return dp[n][m][k] = ans;
}
int32_t main() {
  int n, m, k, t;
  cin >> t;
  memset(dp, -1, sizeof(dp));
  while (t--) {
    scanf(" %d %d %d", &n, &m, &k);
    printf("%d\n", solve(n, m, k));
  }
  return 0;
}
