#include <bits/stdc++.h>
using namespace std;
long long int dp[35][35][55], n, m, k;
inline long long int call(long long int x, long long int y, long long int rem) {
  if (rem == 0) return 0;
  if (rem == (x * y)) return 0;
  if (dp[x][y][rem] != -1) return dp[x][y][rem];
  long long int ans = 1e18;
  for (long long int i = 1; i < y; i++) {
    for (long long int k1 = 0; k1 <= k; k1++) {
      ans = min(ans, x * x + call(x, i, k1) + call(x, y - i, k - k1));
    }
  }
  for (long long int i = 1; i < x; i++) {
    for (long long int k1 = 0; k1 <= k; k1++) {
      ans = min(ans, y * y + call(i, y, k1) + call(x - i, y, k - k1));
    }
  }
  return dp[x][y][rem] = ans;
}
int main() {
  long long int t;
  cin >> t;
  memset(dp, -1, sizeof(dp));
  while (t--) {
    cin >> n >> m >> k;
    cout << call(n, m, k) << "\n";
  }
  return 0;
}
