#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long max(long long a, long long b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
long long min(long long a, long long b) {
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
long long power(long long b, long long e) {
  if (e == 0) return 1;
  if (e % 2)
    return ((b * power((b) * (b), (e - 1) / 2)));
  else
    return power((b) * (b), e / 2);
}
long long modpower(long long b, long long e, long long q) {
  long long MOD = q;
  if (e == 0) return 1;
  if (e % 2)
    return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;
  else
    return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;
}
void dpv(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
void dpv(vector<pair<long long, long long> > v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
void dpv(set<long long> v) {
  for (auto i : v) {
    cout << i << " ";
  }
  cout << endl;
}
long long dp[31][31][51];
long long f(long long a, long long b, long long c) {
  if (dp[a][b][c] || a * b == c || !c) {
    return dp[a][b][c];
  }
  long long ans = 1e18;
  for (long long i = 1; i <= a - i; i++) {
    for (long long j = 0; j <= c; j++) {
      ans = min(ans, b * b + f(a - i, b, j) + f(i, b, c - j));
    }
  }
  for (long long i = 1; i <= b - i; i++) {
    for (long long j = 0; j <= c; j++) {
      ans = min(ans, a * a + f(a, i, j) + f(a, b - i, c - j));
    }
  }
  return dp[a][b][c] = ans;
}
void oblivious() {
  long long a, b, c;
  cin >> a >> b >> c;
  cout << f(a, b, c) << endl;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, 0, sizeof(dp));
  long long t = 1;
  cin >> t;
  while (t--) {
    oblivious();
  }
  return 0;
}
