#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int f[35][35][55];
int main() {
  memset(f, 0x7f, sizeof(f));
  for (int i = 1; i <= 30; i++)
    for (int j = 1; j <= 30; j++) {
      if (i * j <= 50) f[i][j][i * j] = 0;
      f[i][j][0] = 0;
      int nn = min(i * j, 50);
      for (int k = 1; k <= nn; k++) {
        for (int l = 1; l <= i / 2; l++)
          for (int p = 0; p <= min(l * j, k); p++)
            f[i][j][k] =
                min(f[i][j][k], f[l][j][p] + f[i - l][j][k - p] + j * j);
        for (int l = 1; l <= j / 2; l++)
          for (int p = 0; p <= min(l * i, k); p++)
            f[i][j][k] =
                min(f[i][j][k], f[i][l][p] + f[i][j - l][k - p] + i * i);
      }
    }
  int T;
  cin >> T;
  while (T--) {
    scanf("%d%d%d", &n, &m, &k);
    printf("%d\n", f[n][m][k]);
  }
  return 0;
}
