#include <bits/stdc++.h>
using namespace std;
long long dp[55][55][55];
long long DFS(int n, int m, int k) {
  if (k <= 0 || n * m == k) return 0;
  if (dp[n][m][k]) return dp[n][m][k];
  long long now = 0x7f7f7f7f;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j <= k; j++) {
      now = min(now, DFS(i, m, j) + DFS(n - i, m, k - j) + m * m);
    }
  }
  for (int i = 1; i < m; i++) {
    for (int j = 0; j <= k; j++) {
      now = min(now, DFS(n, i, j) + DFS(n, m - i, k - j) + n * n);
    }
  }
  dp[n][m][k] = now;
  return now;
}
int main() {
  int t;
  cin >> t;
  int n, m, k;
  while (t--) {
    scanf("%d%d%d", &n, &m, &k);
    printf("%lld\n", DFS(n, m, k));
  }
  return 0;
}
