/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// upper_bound(all(a),k,greater<int>()) gives first no smaller(not greater) than k

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
const int N=52;
int n,m,k;
int dp[N][N][N];        //dp[n][m][k]
int F(int x,int y,int k)
{
    if(x*y<k) return 1e18;
    if(k==0||x*y==k) return 0;

    if(dp[x][y][k]==-1)
    {
        int ans=1e18;
        for(int i=1;i<=x-i;i++)                 //cut the piece at x=i (2 pieces now of sz i and x-i)
        {
            for(int j=0;j<=k;j++)               //take j from one piece and (k-j) from the other piece
            {
                ans=min(ans,y*y + F(i,y,j) +F(x-i,y,k-j));
            }
        }

        for(int i=1;i<=y-i;i++)
        {
            for(int j=0;j<=k;j++)
            {
                ans=min(ans,x*x + F(x,i,j) +F(x,y-i,k-j));
            }
        }

        dp[x][y][k]=ans;
    }
    return dp[x][y][k];
}
main()
{
IOS;
int t;cin>>t;
while(t--)
{
    cin>>n>>m>>k;
    memset(dp,-1,sizeof(dp));

    cout<<F(n,m,k)<<endl;
}
return 0;
}


/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,n) for(int i=0;i<n;i++)
#define lop(i,a,b) for(int i=a;i<=b;i++)
#define int long long int
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp make_pair
#define sz(a) int((a).size())
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define so(v) sort(all(v))
#define sod(v) sort(allr(v))
#define mfind(c, element) (c.find(element) != c.end())
#define gfind(c, element) (find(all(c),element) != c.end())
#define gfindindex(c, element) (find(all(c),element)-c.begin())
#define vp(x) cout << #x << " --> " << x << endl;
#define cp1(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define cpp1(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define ccp1(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define bsnp np3(low,high,mid);
#define hmm1 high=mid-1;
#define lmp1 low=mid+1;
#define hmp1 high=mid+1;
#define lmm1 low=mid-1;
#define fi first
#define se second
#define endl "\n"
#define np1(x) cout<<#x<<"="<<x<<'\n'
#define np2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define np3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
// upper_bound(all(a),k,greater<int>()) gives first no smaller(not greater) than k

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};//comparison used for sorting set<pair<i,i>,cmp>
bool myComparison(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
//increasing ordr basedd on 2nd
};
const int N=31,K=51;
int n,m,k;
int dp[N][N][K];        //dp[n][m][k]
int F(int x,int y,int k)
{
    if(x*y<k) return 1e18;
    if(k==0||x*y==k) return 0;

    if(dp[x][y][k]==-1)
    {
        int ans=1e18;
        for(int i=1;i<=x-i;i++)                 //cut the piece at x=i (2 pieces now of sz i and x-i)
        {
            for(int j=0;j<=k;j++)               //take j from one piece and (k-j) from the other piece
            {
                ans=min(ans,y*y + F(i,y,j) +F(x-i,y,k-j));
            }
        }

        for(int i=1;i<=y-i;i++)
        {
            for(int j=0;j<=k;j++)
            {
                ans=min(ans,x*x + F(x,i,j) +F(x,y-i,k-j));
            }
        }

        dp[x][y][k]=ans;
    }
    return dp[x][y][k];
}
main()
{
IOS;
int t;cin>>t;
while(t--)
{
    cin>>n>>m>>k;
    memset(dp,-1,sizeof(dp));

    cout<<F(n,m,k)<<endl;
}
return 0;
}


#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
//#define for(i,s,n) for(int i=s;i<n;i++)
#define vii vector<int>
int OO = 1e14;
int dp[31][31][51];
int solve(int i, int j, int rem) {
	if (i * j == rem || !rem) return 0;
	int& ret = dp[i][j][rem];
	if (~ret) return ret;
	ret = OO;
	for (int x = 1; x < i; ++x) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, ((j * j) + solve(x, j, r) + solve(i - x, j, rem - r)));
	    }
	}
	for (int y = 1; y < j; y++) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, (i * i) + solve(i, y, r) + solve(i, j - y, rem - r));
		}
	}
	return ret;
}
signed main()
{
	fast;
	int t = 1, n, m, k;
	cin>>t;
	while (t--)
	{
		cin >> n >> m >> k;
		memset(dp, -1, sizeof dp);
		cout << solve(n, m, k) << endl;
	}
}


#include<bits/stdc++.h>
//#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
//#define for(i,s,n) for(int i=s;i<n;i++)
#define vii vector<int>
int OO = 1e9;
int dp[31][31][51];
int solve(int i, int j, int rem) {
	if (i * j == rem || !rem) return 0;
	int& ret = dp[i][j][rem];
	if (ret) return ret;
	ret = OO;
	for (int x = 1; x < i; ++x) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, ((j * j) + solve(x, j, r) + solve(i - x, j, rem - r)));
	    }
	}
	for (int y = 1; y < j; y++) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, (i * i) + solve(i, y, r) + solve(i, j - y, rem - r));
		}
	}
	return ret;
}
signed main()
{
	fast;
	int t = 1, n, m, k;
	cin>>t;
	while (t--)
	{
		cin >> n >> m >> k;
		cout << solve(n, m, k) << endl;
	}
}


#include<bits/stdc++.h>
//#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
//#define for(i,s,n) for(int i=s;i<n;i++)
#define vii vector<int>
int OO = 1e9;
int dp[31][31][51];
int vid[31][31][51];
int vis;
int solve(int i, int j, int rem) {
	if (i * j == rem || !rem) return 0;
	int& ret = dp[i][j][rem];
	if (vid[i][j][rem] == vis) return ret;
	vid[i][j][rem] = vis;
	ret = OO;
	for (int x = 1; x < i; ++x) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, ((j * j) + solve(x, j, r) + solve(i - x, j, rem - r)));
	    }
	}
	for (int y = 1; y < j; y++) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, (i * i) + solve(i, y, r) + solve(i, j - y, rem - r));
		}
	}
	return ret;
}
signed main()
{
	fast;
	int t = 1, n, m, k;
	cin>>t;
	while (t--)
	{
		vis++;
		cin >> n >> m >> k;
		//memset(dp, -1, sizeof dp);
		cout << solve(n, m, k) << endl;
	}
}


#include<bits/stdc++.h>
//#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
//#define for(i,s,n) for(int i=s;i<n;i++)
#define vii vector<int>
int OO = 1e9;
int dp[31][31][51];
int solve(int i, int j, int rem) {
	if (i * j == rem || !rem) return 0;
	int& ret = dp[i][j][rem];
	if (~ret) return ret;
	ret = OO;
	for (int x = 1; x < i; ++x) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, ((j * j) + solve(x, j, r) + solve(i - x, j, rem - r)));
	    }
	}
	for (int y = 1; y < j; y++) {
		for (int r = 0; r <= rem; r++) {
			ret = min(ret, (i * i) + solve(i, y, r) + solve(i, j - y, rem - r));
		}
	}
	return ret;
}
signed main()
{
	fast;
	int t = 1, n, m, k;
	cin>>t;
	while (t--)
	{
		cin >> n >> m >> k;
		memset(dp, -1, sizeof dp);
		cout << solve(n, m, k) << endl;
	}
}


#include <bits/stdc++.h>
const int N=35,K=1225;
using namespace std;
int dp[N][N][K]={INT_MAX};
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    for(int k=0;k<K;k++)dp[0][0][k]=0;
    for(int i=1;i<N;i++){
        for(int j=1;j<N;j++){
            for(int k=0;k<K;k++)dp[i][j][k]=INT_MAX/100;
            dp[i][j][i*j]=0;
            for(int k=i;k<min(K,i*i);k+=i){
                dp[i][j][k]=min(dp[i][j][k],i*i);
            }
            for(int l=j;l<min(K,i*j);l+=j){
                dp[i][j][l]=min(dp[i][j][l],j*j);
            }
             for(int k=1;k<=min(K,i);k++){
                for(int l=1;l<=min(K,j);l++){
                    for(int pos=1;pos-k*l<=i*j;pos++){
                        if(pos-k*l<0)continue;
                        if(pos>=K)continue;
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+i*i+l*l);
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+k*k+j*j);
                    }
                }
            }
        }
    }
    int t;cin>>t;
    while(t--){
        int n,m,k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
const int N=35,K=1225;
using namespace std;
int dp[N][N][K]={INT_MAX};
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    for(int k=0;k<K;k++)dp[0][0][k]=0;
    for(int i=1;i<N;i++){
        for(int j=1;j<N;j++){
            for(int k=0;k<K;k++)dp[i][j][k]=INT_MAX/100;
            dp[i][j][i*j]=0;
            for(int k=i;k<min(K,i*i);k+=i){
                dp[i][j][k]=min(dp[i][j][k],i*i);
            }
            for(int l=j;l<min(K,i*j);l+=j){
                dp[i][j][l]=min(dp[i][j][l],j*j);
            }
             for(int k=1;k<=min(K,i);k++){
                for(int l=1;l<=min(K,j);l++){
                    for(int pos=1;pos-k*l<=i*j;pos++){
                        if(pos-k*l<0)continue;
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+i*i+l*l);
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+k*k+j*j);
                    }
                }
            }
        }
    }
    int t;cin>>t;
    while(t--){
        int n,m,k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
const int N=35,K=1225;
using namespace std;
int dp[N][N][K]={INT_MAX};
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    for(int k=0;k<K;k++)dp[0][0][k]=0;
    for(int i=1;i<N;i++){
        for(int j=1;j<N;j++){
            for(int k=0;k<K;k++)dp[i][j][k]=INT_MAX/100;
            dp[i][j][i*j]=0;
            for(int k=i;k<=min(K,i*i);k+=i){
                dp[i][j][k]=min(dp[i][j][k],i*i);
            }
            for(int l=j;l<=min(K,i*j);l+=j){
                dp[i][j][l]=min(dp[i][j][l],j*j);
            }
             for(int k=1;k<=min(K,i);k++){
                for(int l=1;l<=min(K,j);l++){
                    for(int pos=1;pos-k*l<=i*j;pos++){
                        if(pos-k*l<0)continue;
                        if(pos>=K)continue;
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+i*i+l*l);
                        dp[i][j][pos-k*l]=min(dp[i][j][pos-k*l],dp[i-k][j-l][pos]+k*k+j*j);
                    }
                }
            }
        }
    }
    int t;cin>>t;
    while(t--){
        int n,m,k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
const int N=35,K=50;
using namespace std;
long long dp[N][N][K];
int calc(int n,int m,int k){
    if(n<=m)swap(n,m);
    if(k==0)return 0;
    if(n*m==k)return 0;
    if(k<0)return INT_MAX/100;
    if(dp[n][m][k]!=-1)return dp[n][m][k];
    int ans=INT_MAX/100;
    for(int i=1;i<n;i++){
        int cst=m*m;
        for(int e=0;e<=k;e++){
            ans=min(ans,cst+calc(n-i,m,k-e)+calc(i,m,e));
        }
    }
    for(int j=1;j<m;j++){
        int cst=n*n;
        for(int e=0;e<=k;e++){
            ans=min(ans,cst+calc(n,m-j,k-e)+calc(n,j,e));
        }
    }
    dp[n][m][k]=ans;
    return dp[n][m][k];
}
int main()
{ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    for(int i=0;i<N;i++){https://codeforces.com/contest/598/submit
        for(int j=0;j<N;j++){
            for(int k=0;k<K;k++)dp[i][j][k]=-1;
        }
    }
    /*for(int i=1;i<=5;i++){
        for(int j=1;j<=5;j++){
            for(int k=1;k<=i*j;k++){
                cout<<i<<' '<<j<<' '<<k<<' '<<calc(i,j,k)<<endl;
            }
        }
    }*/
    int m;
    cin>>m;
    while(m--){
        int a,b,c;cin>>a>>b>>c;
        cout<<calc(a,b,c)<<'\n';
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

const int inf = 1000000000;
int dp[37][37][57];
int break_k(int n, int m, int k)
{
	if (n < 0 || m < 0 || k < 0) return inf;
	if (!k || n * m == k) return 0;
	if (n * m < k) return inf;
	if (dp[n][m][k] != -1) return dp[n][m][k];
	//cout << n << " " << m << " " << k << " " << moves << endl;
	int ans = inf;
	for (int i = 1; i < n; i++)
	{
		ans = min(ans, m * m + break_k(i, m, k));
		if ((n - i) * m <= k)
			ans = min(ans, m * m + break_k(i, m, k - (n - i) * m));
	}
	for (int i = 1; i < m; i++)
	{
		ans = min(ans, n * n + break_k(i, n, k));
		if ((m - i) * n <= k)
			ans = min(ans, n * n + break_k(i, n, k - (m - i) * n));
	}
	dp[n][m][k] = ans;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 37; i++)
	{
		for (int j = 0; j < 37; j++)
		{
			for (int k = 0; k < 57; k++)
			{
				dp[i][j][k] = -1;
			}
		}
	}
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, k;
		cin >> n >> m >> k;
		int ans = break_k(n, m, k);
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

const int inf = 1000000000;
int dp[37][37][57][7];
int break_k(int n, int m, int k, int moves)
{
	if (!k || n * m == k) return 0;
	if (!moves) return inf;
	if (n * m < k) return inf;
	if (dp[n][m][k][moves] != -1) return dp[n][m][k][moves];
	//cout << n << " " << m << " " << k << " " << moves << endl;
	int ans = inf;
	for (int i = 1; i < n; i++)
	{
		ans = min(ans, m * m + break_k(i, m, k, moves - 1));
		if ((n - i) * m <= k)
			ans = min(ans, m * m + break_k(i, m, k - (n - i) * m, moves - 1));
	}
	for (int i = 1; i < m; i++)
	{
		ans = min(ans, n * n + break_k(i, n, k, moves - 1));
		if ((m - i) * n <= k)
			ans = min(ans, n * n + break_k(i, n, k - (n - i) * n, moves - 1));
	}
	dp[n][m][k][moves] = ans;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 37; i++)
	{
		for (int j = 0; j < 37; j++)
		{
			for (int k = 0; k < 57; k++)
			{
				for (int l = 0; l < 7; l++)
					dp[i][j][k][l] = -1;
			}
		}
	}
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, k;
		cin >> n >> m >> k;
		int ans = break_k(n, m, k, 3);
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

const int inf = 1000000000;
int dp[37][37][57][7];
int break_k(int n, int m, int k, int moves)
{
	if (n < 0 || m < 0 || k < 0 || moves < 0) return inf;
	if (!k || n * m == k) return 0;
	if (!moves) return inf;
	if (n * m < k) return inf;
	if (dp[n][m][k][moves] != -1) return dp[n][m][k][moves];
	//cout << n << " " << m << " " << k << " " << moves << endl;
	int ans = inf;
	for (int i = 1; i < n; i++)
	{
		ans = min(ans, m * m + break_k(i, m, k, moves - 1));
		if ((n - i) * m <= k)
			ans = min(ans, m * m + break_k(i, m, k - (n - i) * m, moves - 1));
	}
	for (int i = 1; i < m; i++)
	{
		ans = min(ans, n * n + break_k(i, n, k, moves - 1));
		if ((m - i) * n <= k)
			ans = min(ans, n * n + break_k(i, n, k - (m - i) * n, moves - 1));
	}
	dp[n][m][k][moves] = ans;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 37; i++)
	{
		for (int j = 0; j < 37; j++)
		{
			for (int k = 0; k < 57; k++)
			{
				for (int l = 0; l < 7; l++)
					dp[i][j][k][l] = -1;
			}
		}
	}
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, k;
		cin >> n >> m >> k;
		int ans = break_k(n, m, k, 3);
		cout << ans << "\n";
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

const int inf = 1000000000;
int dp[37][37][57][7];
int break_k(int n, int m, int k, int moves)
{
	if (!k || n * m == k) return 0;
	if (!moves) return inf;
	if (n * m < k) return inf;
	if (dp[n][m][k][moves] != -1) return dp[n][m][k][moves];
	//cout << n << " " << m << " " << k << " " << moves << endl;
	int ans = inf;
	for (int i = 1; i < n; i++)
	{
		ans = min(ans, m * m + break_k(i, m, k, moves - 1));
		if (i * m <= k)
			ans = min(ans, m * m + break_k(i, m, k - i * m, moves - 1));
	}
	for (int i = 1; i < m; i++)
	{
		ans = min(ans, n * n + break_k(i, n, k, moves - 1));
		if (i * n <= k)
			ans = min(ans, n * n + break_k(i, n, k - i * n, moves - 1));
	}
	dp[n][m][k][moves] = ans;
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 37; i++)
	{
		for (int j = 0; j < 37; j++)
		{
			for (int k = 0; k < 57; k++)
			{
				for (int l = 0; l < 7; l++)
					dp[i][j][k][l] = -1;
			}
		}
	}
	int t;
	cin >> t;
	while (t--)
	{
		int n, m, k;
		cin >> n >> m >> k;
		int ans = break_k(n, m, k, 3);
		cout << ans << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i+i <= x; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(i, y, j)+dfs(i, y, k-j));
    for(int i = 1; i+i <= y; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(i, x, j)+dfs(y-i, x, k-j));
        }
    }
    return res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i+i <= x; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(x-i, y, k-j)+dfs(i, y, j));
    for(int i = 1; i+i <= y; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(x, i, j)+dfs(x, y-i, k-j));
        }
    }
    return dp[x][y][k] = res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i <= x/2; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(i, y, j)+dfs(i, y, k-j));
    for(int i = 1; i <= y/2; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(i, x, j)+dfs(y-i, x, k-j));
        }
    }
    return res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i+i <= x; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(x-i, y, j)+dfs(i, y, k-j));
    for(int i = 1; i+i <= y; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(x, i, j)+dfs(x, y-i, k-j));
        }
    }
    return dp[x][y][k] = res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i+i <= x; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(i, y, j)+dfs(i, y, k-j));
    for(int i = 1; i+i <= y; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(x, i, j)+dfs(x, y-i, k-j));
        }
    }
    return dp[x][y][k] = res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;

int dp[35][35][55];

int dfs(int x, int y, int k){
    if(dp[x][y][k]||x*y==k||!k)return dp[x][y][k];
    int res = 0x3f3f3f3f;
    for(int i = 1; i+i <= x; i++)
        for(int j = 0; j <= k; j++)
            res = min(res, y*y+dfs(i, y, j)+dfs(i, y, k-j));
    for(int i = 1; i+i <= y; i++){
        for(int j = 0; j <= k; j++){
            res = min(res, x*x+dfs(i, x, j)+dfs(y-i, x, k-j));
        }
    }
    return dp[x][y][k] = res;
}

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n, m, k;
        cin>>n>>m>>k;
        cout<<dfs(n,m,k)<<endl;
    }
    return 0;
}


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    //#define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e9
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k==0)
    	return 0;
    	if(k<0)
    	return inf;
    	if(n*m<k)
    	return inf;
    	if((n*m)==1)
    	return inf;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        memset(dp,-1,sizeof(dp));
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    #define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k<=0)
    	return 0;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	memset(dp,-1,sizeof(dp));
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    //#define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e9
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k<=0)
    	return 0;
    	if(n*m<k)
    	return inf;

    	if((n*m)==1)
    	return inf;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	memset(dp,-1,sizeof(dp));
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    #define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(n*m<k)
    	return inf;
    	if(k<=0)
    	return 0;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	memset(dp,-1,sizeof(dp));
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    //#define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k<=0)
    	return 0;
    	if(n*m<k)
    	return inf;

    	if(n*m==1)
    	return inf;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	memset(dp,-1,sizeof(dp));
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    #define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k<=0)
    	return 0;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    //#define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e9
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k==0)
    	return 0;
    	if(k<0)
    	return inf;
    	if(n*m<k)
    	return inf;
    	if((n*m)==1)
    	return inf;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;
    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        while(t--){
        	solve();
        }
    }


	#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

    #define ff first
    #define ss second
    #define mp make_pair

    #define pb push_back
    #define endl "\n"

    #define int long long int
    #define double long double

    #define bp __builtin_popcountll
    #define inf 1e17
    const int N=1e5+6;
    const int MOD=1e9+7;
    int dp[31][31][51];
    int fun(int n,int m,int k)
    {
    	if(n*m==k)
    	return 0;
    	if(k<=0)
    	return 0;
    	int &ans=dp[n][m][k];
    	if(ans!=-1)
    	return ans;
    	ans=inf;
    	for(int i=1;i<n;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,m,j)+fun(n-i,m,k-j)+m*m);
    		}
    	}
    	for(int i=1;i<m;i++)
    	{
    		for(int j=0;j<=k;j++)
    		{
    			ans=min(ans,fun(i,n,j)+fun(m-i,n,k-j)+n*n);
    		}
    	}
    	return ans;
    }
    void solve()
    {
    	int n,m,k;
    	cin>>n>>m>>k;

    	int res=fun(n,m,k);
    	cout<<res<<endl;
    }
	signed main()
    {
        FAST
        int t=1;
        cin>>t;
        memset(dp,-1,sizeof(dp));
        while(t--){
        	solve();
        }
    }


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';

const int nmmx = 31, kmx = 51;
int dp[nmmx][nmmx][kmx];

int solve(int n, int m, int k){
    int &ans = dp[n][m][k];
    if(ans!=-1) return ans;
    if(n*m==k || !k) return ans = 0;
    ans = 1e18;
    for(int i = 1; i<= n-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, m*m + solve(i, m, j) + solve(n-i, m, k - j));
        }
    }
    for(int i = 1; i<=m-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, n*n + solve(n, i, j) + solve(n, m-i, k-j));
        }
    }
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // Let's Type Some Shit
    memset(dp, -1, sizeof(dp));
    solve(30, 30, 50);
    int t;cin>>t;
    while(t--){
        int n, m, k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';

const int nmmx = 31, kmx = 51;
int dp[nmmx][nmmx][kmx];

int solve(int n, int m, int k){
    int &ans = dp[n][m][k];
    if(ans!=-1) return ans;
    if(n*m==k || !k) return ans = 0;
    ans = 1e18;
    for(int i = 1; i<= n-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, m*m + solve(i, m, j) + solve(n-i, m, k - j));
        }
    }
    for(int i = 1; i<=m-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, n*n + solve(n, i, j) + solve(n, m-i, k-j));
        }
    }
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // Let's Type Some Shit
    memset(dp, -1, sizeof(dp));
    int t;cin>>t;
    while(t--){
        int n, m, k;cin>>n>>m>>k;
        cout<<solve(n, m, k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';

const int nmmx = 31, kmx = 51;
int dp[nmmx][nmmx][kmx];

int solve(int n, int m, int k){
    int &ans = dp[n][m][k];
    if(ans!=-1) return ans;
    if(n*m==k || !k) return ans = 0;
    ans = 1e18;
    for(int i = 1; i<= n-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, m*m + solve(i, m, j) + solve(n-i, m, k - j));
        }
    }
    for(int i = 1; i<=m-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, n*n + solve(n, i, j) + solve(n, m-i, k-j));
        }
    }
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // Let's Type Some Shit
    memset(dp, -1, sizeof(dp));
    solve(30, 30, 50);
    int t;cin>>t;
    while(t--){
        int n, m, k;cin>>n>>m>>k;
        cout<<solve(n, m, k)<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';

const int nmmx = 31, kmx = 51;
int dp[nmmx][nmmx][kmx];

int solve(int n, int m, int k){
    int &ans = dp[n][m][k];
    if(ans!=-1) return ans;
    if(n*m==k || !k) return ans = 0;
    ans = 1e18;
    for(int i = 1; i<= n-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, m*m + solve(i, m, j) + solve(n-i, m, k - j));
        }
    }
    for(int i = 1; i<=m-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, n*n + solve(n, i, j) + solve(n, m-i, k-j));
        }
    }
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // Let's Type Some Shit
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i<=30; ++i){
        for(int j = 1; j<= 30; ++j){
            for(int k = 1; k<=50; ++k){
                if(i*j==k || !k){
                    dp[i][j][k] = 0;
                    continue;
                }
                int &ans = dp[i][j][k];
                ans = 1e18;
                for(int x = 1; x < i; ++x){
                    for(int y = 0; y<=k; ++y){
                        ans = min(ans, j*j + dp[x][j][y] + dp[i-x][j][k-y]);
                    }
                }
                for(int x = 1; x < j; ++x){
                    for(int y = 0; y <= k; ++y){
                        ans = min(ans, i*i + dp[i][x][y] + dp[i][j-x][k-y]);
                    }
                }
            }
        }
    }
    int t;cin>>t;
    while(t--){
        int n, m, k;cin>>n>>m>>k;
        cout<<dp[n][m][k]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n';

const int nmmx = 31, kmx = 51;
int dp[nmmx][nmmx][kmx];

int solve(int n, int m, int k){
    int &ans = dp[n][m][k];
    if(ans!=-1) return ans;
    if(n*m==k || !k) return ans = 0;
    ans = 1e18;
    for(int i = 1; i<= n-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, m*m + solve(i, m, j) + solve(n-i, m, k - j));
        }
    }
    for(int i = 1; i<=m-1; ++i){
        for(int j = 0; j <= k; ++j){
            ans = min(ans, n*n + solve(n, i, j) + solve(n, n-i, k-j));
        }
    }
    return ans;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // Let's Type Some Shit
    memset(dp, -1, sizeof(dp));
    solve(30, 30, 50);
    int t;cin>>t;
    while(t--){
        int n, m, k;cin>>n>>m>>k;
        cout<<solve(n, m, k)<<endl;
    }
    return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 10000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31][51];

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)
			for(int k = 0; k < 51 ; k++)
				dp[i][j][k] = inf;
}

ll solve(int x,int y, int k){
	if(x*y == k || k == 0)return dp[x][y][k] = 0, dp[y][x][k] = 0, 0;

	if(dp[x][y][k] != inf || x*y < k)return dp[x][y][k];

	for(int i = 1; i < x; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(i,y,j) + solve(x-i,y,k-j) + y*y);
		}
	}
	for(int i = 1; i < y; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(x,i,j) + solve(x,y-i,k-j) + x*x);
		}
	}

	dp[x][y][k] = min(dp[y][x][k],dp[x][y][k]);
	dp[y][x][k] = dp[x][y][k];
	return dp[x][y][k];
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	fill();
	solve(30,30,50);

	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		cout<<dp[n][m][k]<<endl;
	}
	return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 1000000000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31];
ll solve(int x,int y,int k){
	if(x*y == k)return dp[x][y] = 0, dp[y][x] = 0, 0;

	if(dp[x][y] != inf || x*y < k)return dp[x][y];

	for(int i = 1; i < x; i++)
		dp[x][y] = min(min(solve(i,y,k),solve(x - i,y,k)) + y*y,dp[x][y]);

	for(int i = 1; i < y ; i++)
		dp[x][y] = min(min(solve(x,i,k), solve(x,y-i,k)) + x*x,dp[x][y]);

	dp[y][x] = dp[x][y];
	return dp[x][y];
}

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)dp[i][j] = inf;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		fill();
		ll ans = solve(n,m,k);
		fill();
		for(int i = 1; i  <= n ; i++){
			if(i * m > k){
				ans = min(ans,solve((n - i + 1),m,k - (i-1)*m) + n*n);
				break;
			}
		}
		fill();
		for(int i = 1; i  <= m ; i++){
			if(i * n > k){
				ans = min(ans,solve(n,(m - i + 1),k - (i-1)*n) + m*m);
				break;
			}
		}

		cout<<ans<<endl;
	}
	return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 2000000000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31][51];

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)
			for(int k = 0; k < 51 ; k++)
				dp[i][j][k] = inf;
}

ll solve(int x,int y, int k){
	if(x*y == k || k == 0)return dp[x][y][k] = 0, dp[y][x][k] = 0, 0;

	if(dp[x][y][k] != inf || x*y < k)return dp[x][y][k];

	for(int i = 1; i < x; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(i,y,j) + solve(x-i,y,k-j) + y*y);
		}
	}
	for(int i = 1; i < y; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(x,i,j) + solve(x,y-i,k-j) + x*x);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	fill();
	solve(30,30,50);

	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		cout<<dp[n][m][k]<<endl;
	}
	return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 1000000000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31];
ll solve(int x,int y,int k){
	if(x*y == k)return dp[x][y] = 0, dp[y][x] = 0, 0;

	if(dp[x][y] != inf || x*y < k)return dp[x][y];

	for(int i = 1; i < x; i++)
		dp[x][y] = min(min(solve(i,y,k),solve(x - i,y,k)) + y*y,dp[x][y]);

	for(int i = 1; i < y ; i++)
		dp[x][y] = min(min(solve(x,i,k), solve(x,y-i,k)) + x*x,dp[x][y]);

	dp[y][x] = dp[x][y];
	return dp[x][y];
}

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)dp[i][j] = inf;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		fill();
		ll ans = solve(n,m,k);

		for(int i = 1; i  <= n ; i++){
			if(i * m < k){
				fill();
				ans = min(ans,solve((n - i ),m,k - (i)*m) + n*n);
			}
		}
		for(int i = 1; i  <= m ; i++){
			if(i * n < k){
				fill();
				ans = min(ans,solve(n,(m - i),k - i*n) + m*m);
				// break;
			}
		}

		cout<<ans<<endl;
	}
	return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 10000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31][51];

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)
			for(int k = 0; k < 51 ; k++)
				dp[i][j][k] = inf;
}

ll solve(int x,int y, int k){
	if(x*y == k || k == 0)return dp[x][y][k] = 0, dp[y][x][k] = 0, 0;

	if(dp[x][y][k] != inf || x*y < k)return dp[x][y][k];

	for(int i = 1; i < x; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(i,y,j) + solve(x-i,y,k-j) + y*y);
		}
	}
	for(int i = 1; i < y; i++){
		for(int j = 0 ; j <= k ; j++){
			dp[x][y][k] = min(dp[x][y][k],solve(x,i,j) + solve(x,y-i,k-j) + x*x);
		}
	}

	dp[x][y][k] = min(dp[y][x][k],dp[x][y][k]);
	dp[y][x][k] = dp[x][y][k];
	return dp[x][y][k];
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	fill();
	for(int i = 30; i >= 1; i--)
		for(int j =30 ; j >=1 ; j--)
			for(int k = 50 ; k > 0; k--)
					solve(i,j,k);

	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		cout<<dp[n][m][k]<<endl;
	}
	return 0;
}


/*In The Name of ALLAH*/
#include <bits/stdc++.h>
#define inf 1000000000000000000
#define mod  98244353
#define MAX 200011
#define ll long long
#define endl '\n'
using namespace std;

ll dp[31][31];
ll solve(int x,int y,int k){
	if(x*y == k)return dp[x][y] = 0, dp[y][x] = 0, 0;

	if(dp[x][y] != inf || x*y < k)return dp[x][y];

	for(int i = 1; i < x; i++)
		dp[x][y] = min(min(solve(i,y,k),solve(x - i,y,k)) + y*y,dp[x][y]);

	for(int i = 1; i < y ; i++)
		dp[x][y] = min(min(solve(x,i,k), solve(x,y-i,k)) + x*x,dp[x][y]);

	dp[y][x] = dp[x][y];
	return dp[x][y];
}

void fill(){
	for(int i = 0; i < 31; i++)
		for(int j =0; j < 31 ; j++)dp[i][j] = inf;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		int n,m,k;
		cin>>n>>m>>k;
		fill();
		ll ans = solve(n,m,k);
		fill();
		for(int i = 1; i  <= n ; i++){
			if(i * m > k){
				ans = min(ans,solve((n - i + 1),m,k - (i-1)*m) + m*m);
				break;
			}
		}
		fill();
		for(int i = 1; i  <= m ; i++){
			if(i * n > k){
				ans = min(ans,solve(n,(m - i + 1),k - (i-1)*n) + n*n);
				break;
			}
		}

		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define append push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
typedef long long ll;
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
int dp[31][31][51];
int solve(int x,int y,int k)
{
	if(dp[x][y][k]||x*y==k||!k) return dp[x][y][k];
	int mn=1e9+5;
	for(int i=0;i<x;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,y*y+solve(i+1,y,k-j)+solve(x-i-1,y,j));
		}
	}
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,x*x+solve(x,i+1,k-j)+solve(x,y-i-1,j));
		}
	}
	dp[x][y][k]=mn;
	return dp[x][y][k];

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		solve(n,m,k);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define append push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
typedef long long ll;
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
int dp[31][31][51];
int solve(int x,int y,int k)
{
	if(dp[x][y][k]||x*y==k||!k) return dp[x][y][k];
	int mn=1e9+5;
	for(int i=1;i<=x-i;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,y*y+solve(i,y,k-j)+solve(x-i,y,j));
		}
	}
	for(int i=1;i<=y-i;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,x*x+solve(x,i,k-j)+solve(x,y-i,j));
		}
	}
	dp[x][y][k]=mn;
	return dp[x][y][k];

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		cout<<solve(n,m,k)<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define append push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
typedef long long ll;
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
int dp[31][31][51];
int solve(int x,int y,int k)
{
	if(dp[x][y][k]||x*y==k||!k) return dp[x][y][k];
	int mn=1e9+5;
	for(int i=1;i<=x/2;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,y*y+solve(i,y,k-j)+solve(x-i,y,j));
		}
	}
	for(int i=1;i<=y/2;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,x*x+solve(x,i,k-j)+solve(x,y-i,j));
		}
	}
	dp[x][y][k]=mn;
	return dp[x][y][k];

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		cout<<solve(n,m,k)<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define append push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
typedef long long ll;
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
int dp[31][31][51];
int solve(int x,int y,int k)
{
	if(dp[x][y][k]||x*y==k||!k) return dp[x][y][k];
	int mn=1e9+5;
	for(int i=0;i<x;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,y*y+solve(i+1,y,k-j)+solve(x-i-1,y,j));
		}
	}
	for(int i=0;i<y;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,x*x+solve(x,i+1,k-j)+solve(x,y-i-1,j));
		}
	}

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		solve(n,m,k);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define append push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forl(i, n) for(long long i=0;i<n;++i)
typedef long long ll;
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}
int dp[31][31][51];
int solve(int x,int y,int k)
{
	if(dp[x][y][k]||x*y==k||!k) return dp[x][y][k];
	int mn=1e9+5;
	for(int i=1;i<=x-i;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,y*y+solve(i,y,k-j)+solve(x-i,y,j));
		}
	}
	for(int i=1;i<=y-i;i++)
	{
		for(int j=0;j<=k;j++)
		{
			mn=min(mn,x*x+solve(x,i,k-j)+solve(x,y-i,j));
		}
	}
	dp[x][y][k]=mn;
	return dp[x][y][k];

}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		cin>>n>>m>>k;
		solve(n,m,k);
	}
}


#include <bits/stdc++.h>
using namespace std;
int TC;
int visit[33][33][55];

int f(int n, int m, int k) {
    if(n * m < k) return 1e9;
    if(n * m == k || k == 0) return 0;
    auto &r = visit[n][m][k];
    if(!r) {
        r = 1e9;
        for(int i=1;i<n;i++) {
            for(int j=0;j<=k;j++) {
                r = min(r, f(i, m, j) + f(n - i, m, k - j) + m * m);
            }
        }
        for(int i=1;i<n;i++) {
            for(int j=0;j<=k;j++) {
                r = min(r, f(n, i, j) + f(n, m - i, k - j) + n * n);
            }
        }

    }
    return r;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>TC;
    while(TC--) {
        int n, m, k;
        cin>>n>>m>>k;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
                fill(visit[i][j], visit[i][j] + k + 1, 0);
        cout<<f(n, m, k)<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
int TC;
int visit[33][33][55];

int f(int n, int m, int k) {
    if(n * m < k) return 1e9;
    if(n * m == k || k == 0) return 0;
    auto &r = visit[n][m][k];
    if(!r) {
        r = 1e9;
        for(int i=1;i<n;i++) {
            for(int j=0;j<=k;j++) {
                r = min(r, f(i, m, j) + f(n - i, m, k - j) + m * m);
            }
        }
        for(int i=1;i<m;i++) {
            for(int j=0;j<=k;j++) {
                r = min(r, f(n, i, j) + f(n, m - i, k - j) + n * n);
            }
        }

    }
    return r;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>TC;
    while(TC--) {
        int n, m, k;
        cin>>n>>m>>k;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
                fill(visit[i][j], visit[i][j] + k + 1, 0);
        cout<<f(n, m, k)<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
int TC;
int visit[33][33][55];

int f(int n, int m, int k) {
    if(n * m < k) return 1e9;
    if(n * m == k || k == 0) return 0;
    auto &r = visit[n][m][k];
    if(!r) {
        r = 1e9;
        if(r > m * m) {
            for(int i=1;i<n;i++) {
                for(int j=0;j<=k;j++) {
                    if(r <= m * m) continue;
                    r = min(r, f(i, m, j) + f(n - i, m, k - j) + m * m);
                }
            }
        }
        if(r > n * n) {
            for(int i=1;i<m;i++) {
                for(int j=0;j<=k;j++) {
                    r = min(r, f(n, i, j) + f(n, m - i, k - j) + n * n);
                }
            }
        }
    }
    return r;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>TC;
    for(int i=0;i<33;i++)
        for(int j=0;j<33;j++)
            for(int k=0;k<55;k++)
                f(i, j, k);
    while(TC--) {
        int n, m, k;
        cin>>n>>m>>k;
        cout<<f(n, m, k)<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
int TC;
int visit[33][33][55];

int f(int n, int m, int k) {
    if(n * m < k) return 1e9;
    if(n * m == k || k == 0) return 0;
    auto &r = visit[n][m][k];
    if(!r) {
        r = 1e9;
        if(r > m * m) {
            for(int i=1;i<n;i++) {
                for(int j=0;j<=k;j++) {
                    if(r <= m * m) continue;
                    r = min(r, f(i, m, j) + f(n - i, m, k - j) + m * m);
                }
            }
        }
        if(r > n * n) {
            for(int i=1;i<m;i++) {
                for(int j=0;j<=k;j++) {
                    r = min(r, f(n, i, j) + f(n, m - i, k - j) + n * n);
                }
            }
        }
    }
    return r;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>TC;
    while(TC--) {
        int n, m, k;
        cin>>n>>m>>k;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
                fill(visit[i][j], visit[i][j] + k + 1, 0);
        cout<<f(n, m, k)<<'\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
int solve(int n,int m,int k){
	if (n>m) swap(n,m);
	if (k%n==0) return n*n;
	if (k<n) return n*n+1;
	int aa=k/n;
	int ans1=n*n,ans2=2333333;
	int tmp1=solve(n,m-aa,k-aa*n),tmp2=2333333;
	if (k<=n*m/2) tmp2=solve(n,aa+1,k);
	ans1+=min(tmp1,tmp2);
	if (k%m==0 && k%n!=0) ans2=m*m;
	return min(ans1,ans2);
}
int main(){
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		if (k==n*m){
			cout << 0 << endl;
			continue;
		}
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int solve(int n,int m,int k){
	if (n>m) swap(n,m);
	if (k%n==0) return n*n;
	if (k<n) return n*n+1;
	int aa=k/n;
	int ans1=n*n,ans2;
	int tmp1=solve(n,m-aa,k-aa*n),tmp2=2333333;
	if (k<=
	n*m/2) tmp2=solve(n,aa+1,k);
	ans1+=min(tmp1,tmp2);
	if (k%m==0 && k%n!=0) ans2=m*m;
	return min(ans1,ans2);
}
int main(){
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		if (k==n*m){
			cout << 0 << endl;
			continue;
		}
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int solve(int n,int m,int k){
	if (n>m) swap(n,m);
	if (k%n==0) return n*n;
	if (k<=n && k<=m) return n*n+1;
	int aa=k/n;
	int ans1=n*n,ans2;
	ans1+=solve(n,m-aa,k-aa*n);
	if (k%m==0 && k%n!=0) ans2=m*m;
	return min(ans1,ans2);
}
int main(){
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		if (k==n*m){
			cout << 0 << endl;
			continue;
		}
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int solve(int n,int m,int k){
	if (n>m) swap(n,m);
	if (k==n*m) return 0;
	if (k%n==0) return n*n;
	if (k<n) return n*n+1;
	int aa=k/n;
	int ans1=n*n,ans2=2333333;
	int tmp1=solve(n,m-aa,k-aa*n),tmp2=2333333;
	if (k<=n*(m+1)/2) tmp2=solve(n,aa+1,k);
	ans1+=min(tmp1,tmp2);
	if (k%m==0 && k%n!=0) ans2=m*m;
	return min(ans1,ans2);
}
int main(){
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		if (k==n*m){
			cout << 0 << endl;
			continue;
		}
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int inf=0xfffffff;
int dp[31][31][51];
int solve(int n,int m,int k){
	if (dp[n][m][k]!=-1) return dp[n][m][k];
	if (n*m<k) return inf;
	if (k==0 || n*m==k) return 0;
	int ans=inf;
	for (int i=1;i<m;i++)
		for (int j=0;j<=k;j++)
			ans=min(ans,n*n+solve(n,i,j)+solve(n,m-i,k-j));
	for (int i=1;i<n;i++)
		for (int j=0;j<=k;j++)
			ans=min(ans,m*m+solve(i,m,j)+solve(n-i,m,k-j));
	return dp[n][m][k]=ans;
}
int main(){
	memset(dp,-1,sizeof(dp));
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int solve(int n,int m,int k){
	if (n>m) swap(n,m);
	if (k%n==0) return n*n;
	if (k<n) return n*n+1;
	int aa=k/n;
	int ans1=n*n,ans2;
	int tmp1=solve(n,m-aa,k-aa*n),tmp2=2333333;
	if (k<=n*m/2) tmp2=solve(n,aa+1,k);
	ans1+=min(tmp1,tmp2);
	if (k%m==0 && k%n!=0) ans2=m*m;
	return min(ans1,ans2);
}
int main(){
	int t,n,m,k; cin >> t;
	while (t--){
		cin >> n >> m >> k;
		if (k==n*m){
			cout << 0 << endl;
			continue;
		}
		int ans=solve(n,m,k);
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 1e9;
const int MAX_N = 35, MAX_K = 55;
int q, n, m, k;
int dp[MAX_N][MAX_N][MAX_K];

// dp on n, m, k
// INF is impossible (i.e. k > nm)
// otherwise, minimum cost to get exactly k

int main() {
    cin >> q;
    for(int i = 0; i <= 30; i++) {
        for(int j = 0; j <= 30; j++) {
            for(int K = 0; K <= 50; K++) {
                if(i > j) {
                    dp[i][j][K] = dp[j][i][K];
                }else if(K > i * j) {
                    dp[i][j][K] = INF;
                }else if(K == i * j || K == 0) {
                    dp[i][j][K] = 0;
                }else {
                    dp[i][j][K] = INF;
                    for(int l = 1; l < i; l++) {
                        for(int k2 = 0; 2 * k2 <= K; k2++) {
                            dp[i][j][K] = min(dp[i][j][K], j * j + dp[l][j][k2] + dp[i - l][j][K - k2]);
                        }
                    }
                    for(int l = 1; l < j; l++) {
                        for(int k2 = 0; 2 * k2 <= K; k2++) {
                            dp[i][j][K] = min(dp[i][j][K], i * i + dp[i][l][k2] + dp[i][j - l][K - k2]);
                        }
                    }
                }
            }
        }
    }
    while(q--) {
        cin >> n >> m >> k;
        cout << dp[n][m][k] << endl;
    }
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 1e9;
const int MAX_N = 35, MAX_K = 55;
int q, n, m, k;
int dp[MAX_N][MAX_N][MAX_K];

// dp on n, m, k
// INF is impossible (i.e. k > nm)
// otherwise, minimum cost to get exactly k

int main() {
    cin >> q;
    while(q--) {
        cin >> n >> m >> k;
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= m; j++) {
                for(int K = 0; K <= k; K++) {
                    if(K > i * j) {
                        dp[i][j][K] = INF;
                    }else if(K == i * j || K == 0) {
                        dp[i][j][K] = 0;
                    }else {
                        dp[i][j][K] = INF;
                        for(int l = 1; 2 * l <= i; l++) {
                            for(int k2 = 0; 2 * k2 <= K; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], j * j + dp[l][j][k2] + dp[i - l][j][K - k2]);
                            }
                        }
                        for(int l = 1; 2 * l <= j; l++) {
                            for(int k2 = 0; 2 * k2 <= k; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], i * i + dp[i][l][k2] + dp[i][j - l][K - k2]);
                            }
                        }
                    }
                }
            }
        }
        cout << dp[n][m][k] << endl;
    }
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 1e9;
const int MAX_N = 35, MAX_K = 55;
int q, n, m, k;
int dp[MAX_N][MAX_N][MAX_K];

// dp on n, m, k
// INF is impossible (i.e. k > nm)
// otherwise, minimum cost to get exactly k

int main() {
    cin >> q;
    while(q--) {
        cin >> n >> m >> k;
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= m; j++) {
                for(int K = 0; K <= k; K++) {
                    if(i > j) {
                        dp[i][j][K] = dp[j][i][K];
                    }else if(K > i * j) {
                        dp[i][j][K] = INF;
                    }else if(K == i * j || K == 0) {
                        dp[i][j][K] = 0;
                    }else {
                        dp[i][j][K] = INF;
                        for(int l = 1; 2 * l <= i; l++) {
                            for(int k2 = 0; 2 * k2 <= K; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], j * j + dp[l][j][k2] + dp[i - l][j][K - k2]);
                            }
                        }
                        for(int l = 1; 2 * l <= j; l++) {
                            for(int k2 = 0; 2 * k2 <= K; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], i * i + dp[i][l][k2] + dp[i][j - l][K - k2]);
                            }
                        }
                    }
                }
            }
        }
        cout << dp[n][m][k] << endl;
    }
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int INF = 1e9;
const int MAX_N = 35, MAX_K = 55;
int q, n, m, k;
int dp[MAX_N][MAX_N][MAX_K];

// dp on n, m, k
// INF is impossible (i.e. k > nm)
// otherwise, minimum cost to get exactly k

int main() {
    cin >> q;
    while(q--) {
        cin >> n >> m >> k;
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= m; j++) {
                for(int K = 0; K <= k; K++) {
                    if(i > j) {
                        dp[i][j][K] = dp[j][i][K];
                    }else if(K > i * j) {
                        dp[i][j][K] = INF;
                    }else if(K == i * j || K == 0) {
                        dp[i][j][K] = 0;
                    }else {
                        dp[i][j][K] = INF;
                        for(int l = 1; l < i; l++) {
                            for(int k2 = 0; 2 * k2 <= K; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], j * j + dp[l][j][k2] + dp[i - l][j][K - k2]);
                            }
                        }
                        for(int l = 1; l < j; l++) {
                            for(int k2 = 0; 2 * k2 <= K; k2++) {
                                dp[i][j][K] = min(dp[i][j][K], i * i + dp[i][l][k2] + dp[i][j - l][K - k2]);
                            }
                        }
                    }
                }
            }
        }
        cout << dp[n][m][k] << endl;
    }
}


# include <bits/stdc++.h>

using namespace std;

const int xn = 3e1;
const int xk = 5e1;
int dp[xn][xn][xk];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=xn; i++){
		for (int j=1; j<=xn; j++){
			for (int k=0; k<=xk; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					break;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		cout << dp[n][m][k] << endl;
	}
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int xn = 3e1+1;
const int xk = 5e1+1;
const int xans = 4.1e4;
ll dp[xn][xn][xk];
ll ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=30; i++){
		for (int j=1; j<=30; j++){
			for (int k=0; k<=50; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					continue;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=1; l<=(i)/2; l++)
					for (int p=0; p<=k; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=1; l<=(j)/2; l++)
					for (int p=0; p<=k; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int xn = 3e1+1;
const int xk = 5e1+1;
const int xans = 4.1e4;
ll dp[xn][xn][xk];
ll ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=30; i++){
		for (int j=1; j<=30; j++){
			for (int k=0; k<=50; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					break;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int xn = 3e1;
const int xk = 5e1;
const int xans = 4.1e4;
ll dp[xn][xn][xk];
ll ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=xn; i++){
		for (int j=1; j<=xn; j++){
			for (int k=0; k<=xk; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					break;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int xn = 3e1+1;
const int xk = 5e1+1;
const int xans = 4.1e4;
ll dp[xn][xn][xk];
ll ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=30; i++){
		for (int j=1; j<=30; j++){
			for (int k=0; k<=50; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					continue;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

const int xn = 3e1;
const int xk = 5e1;
const int xans = 4.1e4;
int dp[xn][xn][xk];
int ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=xn; i++){
		for (int j=1; j<=xn; j++){
			for (int k=0; k<=xk; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9;
					break;
				}
				dp[i][j][k] = 1e9;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


# include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int xn = 3e1+1;
const int xk = 5e1+1;
const int xans = 4.1e4;
ll dp[xn][xn][xk];
ll ans[xans];

int main(){
	int t;
	cin >> t;
	for (int i=1; i<=xn; i++){
		for (int j=1; j<=xn; j++){
			for (int k=0; k<=xk; k++){
				if (k == 0 or k == i*j) continue;
				else if (k > i*j){
					dp[i][j][k] = 1e9+10;
					break;
				}
				dp[i][j][k] = 1e9+10;
				for (int l=0; l<=i/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], j*j+dp[l][j][p]+dp[i-l][j][k-p]);
				for (int l=0; l<=j/2; l++)
					for (int p=0; p<=k/2; p++) dp[i][j][k] = min(dp[i][j][k], i*i+dp[i][l][p]+dp[i][j-l][k-p]);
			}
		}
	}
	for (int i=0; i<t; i++){
		int n, m, k;
		cin >> n >> m >> k;
		ans[i] = dp[n][m][k];
	}
	for (int i=0; i<t; i++) cout << ans[i] << endl;
	return 0;
}


// 日本語のランダムな単語、
// 日本語が読めるなら
// おそらくそれはあなたにとって役に立たないでしょう。
// さらにランダムな単語
// それを詩のように見せましょう
// 今、他の人のために、
// 次の行は私を見つけるのに役立ちます
//「私は自由なエルフです」

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)          x.begin(), x.end()
#define sz(x)           (int)x.size()
#define pb(x)           push_back(x)
#define deb(x)          cout << #x << " : " << x << endl;

#define ll              long long
// #define int             long long
#define double			long double

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const double PI = acos((double) - 1.0);
const int N = 100000 + 10;

struct point {
	double x, y;
	int idx;
	double ang;
};

bool cmp(const point& a, const point& b) {
	return a.ang + 1e-10 < b.ang;
}

void solve() {
	int n;
	cin >> n;
	vector<point> pts(n);
	for (int i = 0; i < n; ++i) {
		cin >> pts[i].x >> pts[i].y;
		pts[i].idx = i + 1;
		pts[i].ang = atan2(pts[i].y, pts[i].x) + 2 * PI;
		while (pts[i].ang >= 2 * PI) pts[i].ang -= 2 * PI;
	}
	sort(all(pts), cmp);
	pts.pb(pts[0]);
	pair<double, pair<int, int>> ans = {1e9, {0, 0}};
	for (int i = 1; i <= n; ++i) {
		ans = min(ans, make_pair(min(abs(pts[i].ang - pts[i - 1].ang), 2 * PI - abs(pts[i].ang - pts[i - 1].ang)),
		                         make_pair(pts[i].idx, pts[i - 1].idx)));
	}
	cout << ans.second.first << ' ' << ans.second.second;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}


// 日本語のランダムな単語、
// 日本語が読めるなら
// おそらくそれはあなたにとって役に立たないでしょう。
// さらにランダムな単語
// それを詩のように見せましょう
// 今、他の人のために、
// 次の行は私を見つけるのに役立ちます
//「私は自由なエルフです」

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)          x.begin(), x.end()
#define sz(x)           (int)x.size()
#define pb(x)           push_back(x)
#define deb(x)          cout << #x << " : " << x << endl;

#define ll              long long
#define int             long long

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const double PI = acos(-1);
const int N = 100000 + 10;

int dp[35][35][905];

int solve(int a, int b, int k) {
	if (k > a * b) return 1e15;
	if (k == a * b) return 0;
	if (k == 0) return 0;

	int& ans = dp[a][b][k];
	if (ans != -1) return ans;

	ans = 1e15;
	for (int i = 1; i < a; ++i) {
		for (int j = 0; j <= k; ++j) {
			ans = min(ans, solve(i, b, j) + solve(a - i, b, k - j) + b * b);
		}
	}
	for (int i = 1; i < b; ++i) {
		for (int j = 0; j <= k; ++j) {
			ans = min(ans, solve(a, i, j) + solve(a, b - i, k - j) + a * a);
		}
	}
	return ans;
}

void solve() {
	int a, b;
	cin >> a >> b;
	int k;
	cin >> k;
	cout << solve(a, b, k);
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	cin >> t;
	memset(dp, -1, sizeof dp);
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}


// 日本語のランダムな単語、
// 日本語が読めるなら
// おそらくそれはあなたにとって役に立たないでしょう。
// さらにランダムな単語
// それを詩のように見せましょう
// 今、他の人のために、
// 次の行は私を見つけるのに役立ちます
//「私は自由なエルフです」

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define all(x)          x.begin(), x.end()
#define sz(x)           (int)x.size()
#define pb(x)           push_back(x)
#define deb(x)          cout << #x << " : " << x << endl;

#define ll              long long
// #define int             long long

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

const int MOD1 = 1000000007;
const int MOD2 = 998244353;
const double PI = acos(-1);
const int N = 100000 + 10;

int dp[35][35][905];

int solve(int a, int b, int k) {
	if (k > a * b) return 1e15;
	if (k == a * b) return 0;
	if (k == 0) return 0;

	int& ans = dp[a][b][k];
	if (ans != -1) return ans;

	ans = 1e15;
	for (int i = 1; i < a; ++i) {
		for (int j = 0; j <= k; ++j) {
			ans = min(ans, solve(i, b, j) + solve(a - i, b, k - j) + b * b);
		}
	}
	for (int i = 1; i < b; ++i) {
		for (int j = 0; j <= k; ++j) {
			ans = min(ans, solve(a, i, j) + solve(a, b - i, k - j) + a * a);
		}
	}
	return ans;
}

void solve() {
	int a, b;
	cin >> a >> b;
	int k;
	cin >> k;
	cout << solve(a, b, k);
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	cin >> t;
	memset(dp, -1, sizeof dp);
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}


t = int(input())
for j in range(t):
    q = set()
    count = 1
    dude = []
    s = input()
    s = " " + s + " "
    m = s[0]
    for i in range(len(s)):
        if i == 0:
            continue
        if m == s[i]:
            count += 1
        else:
            if count % 2 == 1:
                q.add(m)
            m = s[i]
            count = 1
    for ii in q:
        if ii == " ":
            continue
        dude.append(ii)
    dude.sort()
    print("".join((map(str, dude))))


t = int(input())
for j in range(t):
    q = set()
    dude = []
    s = input()
    s = " " + s + " "
    for i in range(len(s)-1):
        if s[i+1] != s[i] and s[i] != s[i-1]:
            q.add(s[i])
    for ii in q:
        dude.append(ii)
    dude.sort()
    print("".join((map(str, dude))))


n = int(input())

for _ in range(n):
    string = str(input())
    result = set()
    acc = 0
    value = ""
    for i in range(len(string)):
        if string[i] == value or value == "":
            value = string[i]
            acc += 1
        else:
            if acc % 2 != 0:
                result.add(value)
            value = string[i]
            acc = 1
    if acc % 2 != 0:
        result.add(value)
    print("".join(result))


n = int(input())

for _ in range(n):
    string = str(input())

    result = set()

    if len(string) == 1:
        print(string[0])
    else:
        for i in range(len(string)):
            if i == 0:
                if string[i+1] != string[i]:
                    result.add(string[i])
            elif i == len(string)-1:
                if string[i-1] != string[i]:
                    result.add(string[i])
            elif i > 0 and i < len(string)-1:
                if string[i+1] != string[i] and string[i-1] != string[i]:
                    result.add(string[i])
        print("".join(sorted(result)))


n = int(input())

for _ in range(n):
    string = str(input())
    result = set()
    acc = 0
    value = ""
    for i in range(len(string)):
        if string[i] == value or value == "":
            value = string[i]
            acc += 1
        else:
            if acc % 2 != 0:
                result.add(value)
            value = string[i]
            acc = 1
    if acc % 2 != 0:
        result.add(value)
    print("".join(sorted(result)))


t=int(input())
while t:
	str=input()
	res=set()
	if(len(str)==1):
		print(str)
	else:
		i=0
		while i<len(str)-1:
			if str[i]!=str[i+1]:
				res.add(str[i])
				i+=1
			else:
				i+=2
		if str[len(str)-1]!=str[len(str)-2]:
			res.add(str[len(str)-1])
		res=sorted(res)
		ans="".join(res)
		print(ans)

	t-=1


t=int(input())
while t:
	str=input()
	res=set()
	if(len(str)==1):
		print(str)
	else:
		i=0
		n=len(str)
		while i<n:
			c=0
			ch=str[i]
			while i<n and str[i]==ch:
				c+=1
				i+=1
			if c%2!=0:
				res.add(ch)
		if(str[n-1]!=str[n-2]):
			res.add(str[n-1])
		res=sorted(res)
		ans="".join(res)
		print(ans)
	t-=1


t=int(input())
while t:
	str=input()
	res=set()
	if(len(str)==1):
		print(str)
	else:
		i=0
		while i<len(str)-1:
			if str[i]!=str[i+1]:
				res.add(str[i])
				i+=1
			else:
				i+=2
		if str[len(str)-1]!=str[len(str)-2]:
			res.add(str[len(str)-1])
		print("".join(res))
	t-=1


t=int(input())
for i in range(t):
    s=input()
    j=0
    a=''
    while(j<len(s)):
        k=s[j]
        count=0
        while(s[j]==k):
            count+=1
            j+=1
            if(j==len(s)):
                break
        if(count%2==1):
            a+=k
    if(len(a)>0):
        ans=[k for k in a]
        ans.sort()
        a=''
        for item in ans:
            a+=item
        print (a)
    else:
        print (" ")


t=int(input())
from collections import Counter
for i in range(t):
    s=input()
    j=0
    a=''
    while(j<len(s)):
        k=s[j]
        count=0
        while(s[j]==k):
            count+=1
            j+=1
            if(j==len(s)):
                break
        if(count%2==1):
            a+=k
    if(len(a)>0):
        c=Counter(a)
        a=list(c.keys())
        a.sort()
        ans=''
        for item in a:
            ans+=item
        print (ans)
    else:
        print (" ")


t=int(input())
for i in range(t):
    s=input()
    j=0
    a=''
    while(j<len(s)):
        k=s[j]
        count=0
        while(s[j]==k):
            count+=1
            j+=1
            if(j==len(s)):
                break
        if(count%2==1):
            a+=k
    print (a)


tests = int(input())

for t in range(tests):
    correct = []
    inp = input()
    c = 0
    while c < len(inp):
        if (c == len(inp) - 1):
            correct.append(inp[c])
        elif (inp[c] == inp[c + 1]):
            c += 1
        else:
            correct.append(inp[c])
        c += 1

    correct.sort()
    print(correct)


tests = int(input())

for t in range(tests):
    correct = []
    inp = input()
    c = 0
    while c < len(inp):
        if (c == len(inp) - 1):
            correct.append(inp[c])
        elif (inp[c] == inp[c + 1]):
            c += 1
        else:
            correct.append(inp[c])
        c += 1

    correct.sort()
    print(*correct, sep='')


tests = int(input())

for t in range(tests):
    correct = []
    inp = input()
    c = 0
    while c < len(inp):
        if (c == len(inp) - 1):
            correct.append(inp[c])
        elif (inp[c] == inp[c + 1]):
            c += 1
        else:
            correct.append(inp[c])
        c += 1

    correct.sort()
    print(*correct)


tests = int(input())

for t in range(tests):
    correct = set()
    inp = input()
    c = 0
    while c < len(inp):
        if (c == len(inp) - 1):
            correct.add(inp[c])
        elif (inp[c] == inp[c + 1]):
            c += 1
        else:
            correct.add(inp[c])
        c += 1

    l = list(correct)
    l.sort()
    print(*l, sep='')


for _ in range(int(input())):
    s = input()
    for i in range(26):
        s = s.replace(chr(97+i)*2, '')
    print(''.join(sorted(s)))


for _ in range(int(input())):
    s = input()
    if len(s) == 1:
        print(s)
    else:
        res = set()
        i = 1
        prev_s = s[0]
        counter = 1

        while i<len(s):
            if prev_s == s[i]:
                counter += 1
                i += 1
            elif prev_s != s[i]:
                if counter % 2 == 0:
                    prev_s = s[i]
                else:
                    res.add(prev_s)
                    prev_s = s[i]
                i +=1
                counter = 1

        if counter % 2 == 1:
            res.add(prev_s)
        print(''.join(sorted(res)))


for _ in range(int(input())):
    s = input()
    for i in range(26):
        s = s.replace(chr(97+i)*2, '')
    print(''.join(sorted(set(s))))


for _ in range(int(input())):
    a=input();s=sorted(set(a));ans=''
    for i in s:
        if 2*a.count(2*i)!=a.count(i):ans+=i
    print(ans)


for _ in range(int(input())):
    p=input();s=[p[0]];n=len(p)
    for i in range(1,n):
        s.append(p[i])
        if len(s)>=2 and s[-1]==s[-2]:s.pop(-1);s.pop(-1)
    print(*sorted(set(s)),sep="")


for _ in range(int(input())):
    p=input();i=0;s=set();n=len(p)
    if n==1:print(p)
    else:
        while i<n-1:
            if p[i+1]==p[i]:i+=2
            else:s.add(p[i]);i+=1
        if p[-1]!=p[-2]:s.add(p[-1])
        print(*sorted(s),sep="")


t=int(input())
for i in range(t):
    # a=list(map(int,input().strip().split()))
    a=list(input())
    if(len(a)<=1):
        print("".join(a))
        continue
    # if(len(a)==2):

    op=[0]*26
    ispr=[0]*26
    ispr[ord(a[0])-ord('a')]=1
    if(a[0]==a[1]):
        x=0
    else:
        op[ord(a[0])-ord('a')]=1
    if(a[-1]==a[-2]):
        x=0
    else:
        op[ord(a[-1])-ord('a')]=1
    ispr[ord(a[-1])-ord('a')]=1
    for j in range(1,len(a)-1):
        ispr[ord(a[j])-ord('a')]=1
        if(a[j]==a[j-1] or a[j]==a[j+1]):
            # op[ord(a[j])-ord('a')]=1
            continue
        else:
            op[ord(a[j])-ord('a')]=1
    ans=[]
    for j in range(26):
        if(ispr[j]):
            if(op[j]):
            #     continue
            # else:
                ans.append(chr(j+ord('a')))
    print("".join(ans))


t=int(input())
for i in range(t):
    # a=list(map(int,input().strip().split()))
    a=list(input())
    # if(len(a)<=1):
    #     print("".join(a))
    #     continue
    # # if(len(a)==2):

    # op=[0]*26
    # ispr=[0]*26
    # ispr[ord(a[0])-ord('a')]=1
    # if(a[0]==a[1]):
    #     x=0
    # else:
    #     op[ord(a[0])-ord('a')]=1
    # if(a[-1]==a[-2]):
    #     x=0
    # else:
    #     op[ord(a[-1])-ord('a')]=1
    # ispr[ord(a[-1])-ord('a')]=1
    # for j in range(1,len(a)-1):
    #     ispr[ord(a[j])-ord('a')]=1
    #     if(a[j]==a[j-1] or a[j]==a[j+1]):
    #         # op[ord(a[j])-ord('a')]=1
    #         continue
    #     else:
    #         op[ord(a[j])-ord('a')]=1
    # ans=[]
    # for j in range(26):
    #     if(ispr[j]):
    #         if(op[j]):
    #         #     continue
    #         # else:
    #             ans.append(chr(j+ord('a')))
    # print("".join(ans))

    x=len(a)
    j=0
    op=[0]*26
    while(j<x):
        c=1
        while(j<x-1 and a[j]==a[j+1]):
            j+=1
            c+=1
        if(c%2):
            op[ord(a[j])-ord('a')]=1
        j+=1
    ans=[]
    for j in range(26):
        if(op[j]):
            # if(op[j]):
            #     continue
            # else:
            ans.append(chr(j+ord('a')))
    print("".join(ans))


t=int(input())
for i in range(t):
    # a=list(map(int,input().strip().split()))
    a=list(input())
    if(len(a)<=1):
        print("".join(a))
        continue
    op=[0]*26
    ispr=[0]*26
    ispr[ord(a[0])-ord('a')]=1
    if(a[0]==a[1]):
        x=0
    else:
        op[ord(a[0])-ord('a')]=1
    if(a[-1]==a[-2]):
        x=0
    else:
        op[ord(a[0])-ord('a')]=1
    ispr[ord(a[-1])-ord('a')]=1
    for j in range(1,len(a)-1):
        ispr[ord(a[j])-ord('a')]=1
        if(a[j]==a[j-1] or a[j]==a[j+1]):
            # op[ord(a[j])-ord('a')]=1
            continue
        else:
            op[ord(a[j])-ord('a')]=1
    ans=[]
    for j in range(26):
        if(ispr[j]):
            if(op[j]):
            #     continue
            # else:
                ans.append(chr(j+ord('a')))
    print("".join(ans))


for _ in range(int(input())):
    s = input()
    c = 1
    st = set()
    e = 0
    for i in range(len(s)):
        if i == 0:
            e = s[0]
            if len(s) == 1:
                st.add(e)
            continue
        if s[i] == e:
            c += 1
        else:
            if c % 2 == 1:
                st.add(e)
            c = 1
            e = s[i]
    if c % 2 == 1:
        st.add(s[len(s) - 1])
    k = ''.join(list(st))
    print(k)


for _ in range(int(input())):
    s = input()
    c = 1
    st = set()
    e = 0
    for i in range(len(s)):
        if i == 0:
            e = s[0]
            if len(s) == 1:
                st.add(e)
            continue
        if s[i] == e:
            c += 1
        else:
            if c % 2 == 1:
                st.add(e)
            c = 1
            e = s[i]
    if c % 2 == 1:
        st.add(s[len(s) - 1])
    k = ''.join(sorted(list(st)))
    print(k)


for _ in range(int(input())):
    s = input()
    c = 1
    st = set()
    e = 0
    for i in range(len(s)):
        if i == 0:
            e = s[0]
            if len(s) == 1:
                st.add(e)
            continue
        if s[i] == e:
            c += 1
        else:
            if c % 2 == 1:
                st.add(e)
            c = 1
            e = s[i]
    if c % 2 == 1:
        st.add(s[len(s) - 1])
    print(*st)


n = int(input())
for _ in range(n):
	a = input()
	b = set(a)
	for i in b:
		if a.count(i)/2 != a.count(i*2):
			print(i,end = " ")
	print()


n = int(input())
for _ in range(n):
	a = input()
	s = ""
	for i in a:
		if a.count(i)/2 != a.count(i*2):
			if i not in s:
				s+=i
	print(s)


n = int(input())
for _ in range(n):
	a = input()
	s = ""
	for i in a:
		if a.count(i)/2 != a.count(i*2):
			if i not in s:
				s+=i
	z = list(s)
	z.sort()
	print(*z,sep = "")


from sys import stdin
t=int(stdin.readline().rstrip())
while t>0:
    s=stdin.readline().rstrip()
    st=s[0]
    c=1
    for i in range(1,len(s)):
        if s[i]==s[i-1]:
            c+=1
            if c%2==0:
                st=st[:len(st)-1]
            else:
                st+=s[i]
        else:
            st+=s[i]
            c=1
    l=list(st)
    l.sort()
    d=dict()
    for i in l:
        if i not in d:
            d[i]=1
        else:
            d[i]+=1
    for i in d.keys():
        print(str(i),end="")
    print()
    t-=1


t=int(input().rstrip())
while t>0:
    s=input().rstrip()
    st=s[0]
    for i in range(1,len(s)):
        if s[i]==s[i-1]:
            st=st[:len(st)-1]
        else:
            st+=s[i]
    p=list(st)
    p.sort()
    st=''.join(p)
    print(st)
    t-=1


t=int(input().rstrip())
while t>0:
    s=input().rstrip()
    st=s[0]
    c=1
    for i in range(1,len(s)):
        if s[i]!=s[i-1]:
            c=1
        else:
            c+=1
        if c%2==0:
            st=st[:len(st)-1]
        else:
            st+=s[i]
    p=list(st)
    p.sort()
    st=''.join(p)
    print(st)
    t-=1


from sys import stdin
t=int(stdin.readline().rstrip())
while t>0:
    s=stdin.readline().rstrip()
    st=s[0]
    c=1
    for i in range(1,len(s)):
        if s[i]==s[i-1]:
            c+=1
            if c%2==0:
                st=st[:len(st)-1]
            else:
                st+=s[i]
        else:
            st+=s[i]
            c=1
    l=list(st)
    l.sort()
    st=''.join(l)
    print(st)
    t-=1


t=int(input().rstrip())
while t>0:
    s=input().rstrip()
    st=s[0]
    for i in range(1,len(s)):
        if s[i]==s[i-1]:
            st=st[:len(st)-1]
        else:
            st+=s[i]
    print(st)
    t-=1


t = int(input())
for x in range(t):
    l1 = list(input())
    if len(l1)==1:
        print(l1[0])
    elif len(l1)==2:
        if l1[0]==l1[1]:
            print()
        else:
            c = sorted[l1[0],l1[1]]
            print("".join(c))
    else:
        i=0
        ans=[]
        while i<len(l1):
            ruined=0
            if i!=0 and l1[i]==l1[i-1]:
                ruined=1
            if not ruined and i!=len(l1)-1 and l1[i]==l1[i+1]:
                ruined=1
            if not ruined:
                ans.append(l1[i])
            i+=1
        ans.sort()
        print("".join(ans))


t = int(input())
for x in range(t):
    l1 = list(input())
    if len(l1)==1:
        print(l1[0])
    elif len(l1)==2:
        if l1[0]==l1[1]:
            print()
        else:
            c = sorted[l1[0],l1[1]]
            print("".join(c))
    else:
        i=0
        ans=[]
        while i<len(l1):
            ruined=0

            if i!=0 and l1[i]==l1[i-1]:
                ruined=1
            if not ruined and i!=len(l1)-1 and l1[i]==l1[i+1]:
                ruined=1
            if not ruined:
                ans.append(l1[i])
            i+=1
        ans.sort()
        print("".join(ans))


t = int(input())
for x in range(t):
    l1 = list(input())
    if len(l1)==1:
        print(l1[0])
    elif len(l1)==2:
        if l1[0]==l1[1]:
            print()
        else:
            c = sorted([l1[0],l1[1]])
            print("".join(c))
    else:
        i=0
        ans=[]
        while i<len(l1):
            targ = l1[i]
            j=1
            i+=1
            while i<len(l1) and l1[i]==targ:
                i+=1
                j+=1
            if j%2 and targ not in ans:
                ans.append(targ)

        ans.sort()
        print("".join(ans))


t = int(input())
for x in range(t):
    l1 = list(input())
    if len(l1)==1:
        print(l1[0])
    elif len(l1)==2:
        if l1[0]==l1[1]:
            print()
        else:
            c = sorted([l1[0],l1[1]])
            print("".join(c))
    else:
        i=0
        ans=[]
        while i<len(l1):
            ruined=0
            if i!=0 and l1[i]==l1[i-1]:
                ruined=1
            if not ruined and i!=len(l1)-1 and l1[i]==l1[i+1]:
                ruined=1
            if not ruined and l1[i] not in ans:
                ans.append(l1[i])
            i+=1
        ans.sort()
        print("".join(ans))


t = int(input())
for x in range(t):
    l1 = list(input())
    if len(l1)==1:
        print(l1[0])
    elif len(l1)==2:
        if l1[0]==l1[1]:
            print()
        else:
            c = sorted[l1[0],l1[1]]
            print("".join(c))
    else:
        i=0
        ans=[]
        while i<len(l1):
            ruined=0
            if i!=0 and l1[i]==l1[i-1]:
                ruined=1
            if not ruined and i!=len(l1)-1 and l1[i]==l1[i+1]:
                ruined=1
            if not ruined and l1[i] not in ans:
                ans.append(l1[i])
            i+=1
        ans.sort()
        print("".join(ans))


from sys  import stdin,stdout
from collections  import *
from math import gcd,floor,ceil
from bisect import bisect_left as bl
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')
ANS=[]

def solve():
    s=st()
    n=len(s)
    s=s[::-1]
    ans=''
    i=0
    while i<n:
        c=1
        x=s[i]
        i+=1
        while i<n and s[i]==x:
            i+=1
            c+=1
        if c%2:
            ans+=x
    pr(ans)

for _ in range(inp()):
    solve()


from sys  import stdin,stdout
from collections  import *
from math import gcd,floor,ceil
from bisect import bisect_left as bl
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')
ANS=[]

def solve():
    s=st()
    s=s[::-1]
    ans=''
    n=len(s)
    x=''
    i=0
    if n&1:
        x=s[0]
        i=1
    while i<len(s):
        if i==len(s)-1:
            ans+=s[i]
            i+=1
            continue
        if s[i]==s[i+1]:
            i+=2
        else:
            ans+=s[i]
            i+=1
    pr(ans+x)

for _ in range(inp()):
    solve()


from sys  import stdin,stdout
from collections  import *
from math import gcd,floor,ceil
from bisect import bisect_left as bl
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')
ANS=[]

def solve():
    s=st()
    n=len(s)
    j=n-1
    ans=''
    while j>=0:
        if j-1>=0:
            if s[j]!=s[j-1]:
                ans+=s[j]
                j-=1
            else:
                j-=2
        else:
            ans+=s[j]
            j-=1
    pr(ans)

for _ in range(inp()):
    solve()


from sys  import stdin,stdout
from collections  import *
from math import gcd,floor,ceil
from bisect import bisect_left as bl
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
INF=float('inf')
ANS=[]

def solve():
    s=st()
    n=len(s)
    s=s[::-1]
    ans=''
    i=0
    p=set()
    while i<n:
        c=1
        x=s[i]
        i+=1
        while i<n and s[i]==x:
            i+=1
            c+=1
        if c%2:
            p.add(x)
    for i in range(97,97+26):
        if chr(i) in p:
            print(chr(i),end='')
    print()

for _ in range(inp()):
    solve()


for nt in range(int(input())):
	s = input()
	n = len(s)
	if n==1:
		print (s[0])
		continue
	g = [[s[0],1]]
	prev = s[0]
	for i in range(1,n):
		if s[i]==prev:
			g[-1][1] += 1
		else:
			prev = s[i]
			g.append([prev,1])
	ans = []
	for i in g:
		if i[1]%2:
			ans.append(i[0])
	ans = set(ans)
	ans.sort()
	for i in ans:
		print (i,end="")
	print ()


for nt in range(int(input())):
	s = input()
	n = len(s)
	if n==1:
		print (s[0])
		continue
	g = [[s[0],1]]
	prev = s[0]
	for i in range(1,n):
		if s[i]==prev:
			g[-1][1] += 1
		else:
			prev = s[i]
			g.append([prev,1])
	ans = []
	for i in g:
		if i[1]%2:
			ans.append(i[0])
	ans = list(set(ans))
	ans.sort()
	for i in ans:
		print (i,end="")
	print ()


for nt in range(int(input())):
	s = input()
	n = len(s)
	if n==1:
		print (s[0])
		continue
	g = [[s[0],1]]
	prev = s[0]
	for i in range(1,n):
		if s[i]==prev:
			g[-1][1] += 1
		else:
			prev = s[i]
			g.append([prev,1])
	ans = []
	for i in g:
		if i[1]%2:
			ans.append(i[0])
	ans.sort()
	for i in ans:
		print (i,end="")
	print ()


for nt in range(int(input())):
	s = input()
	n = len(s)
	if n==1:
		print (s[0])
		continue
	a = {}
	if s[0]!=s[1]:
		a[s[0]] = 0
	for i in range(1,len(s)-1):
		if s[i]!=s[i-1] and s[i]!=s[i+1]:
			a[s[i]] = 1
	if s[-1]!=s[-2]:
		a[s[-1]] = 1
	ans = []
	for i in a:
		ans.append(i)
	ans.sort()
	for i in ans:
		print (i,end="")
	print ()


from sys import stdin
from sys import setrecursionlimit as SRL

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

q = int(input())
while q:
    s = list(map(str,input().strip()))
    s += ['0']
    pre = s[0]
    cnt = 1
    ans = set()
    for i in s[1:]:
        if i!=pre:
            if cnt == 1:
                ans.add(pre)
            cnt = 0
        cnt += 1
        pre = i
    print(''.join(ans))
    q -= 1


from sys import stdin
from sys import setrecursionlimit as SRL

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

q = int(input())
while q:
    s = list(map(str,input().strip()))
    s+=['0']
    pre = s[0]
    cnt = 1
    ans = set()
    for i in s[1:]:
        if i!=pre:
            if cnt %2:
                ans.add(pre)
            cnt = 0
        cnt += 1
        pre = i
    aa = []
    for i in ans:
        aa.append(i)
    aa = sorted(aa)
    ans = ''.join(aa)
    print(ans)
    q -= 1


from sys import stdin
from sys import setrecursionlimit as SRL

SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

q = int(input())
while q:
    s = list(map(str,input().strip()))
    s += ['0']
    pre = s[0]
    cnt = 1
    ans = set()
    for i in s[1:]:
        if i!=pre:
            if cnt == 1:
                ans.add(pre)
            cnt = 0
        cnt += 1
        pre = i
    aa = []
    for i in ans:
        aa.append(i)
    aa = sorted(aa)
    ans = ''.join(aa)
    print(ans)
    q -= 1


n = int(input())
for _ in range(n):
    s = input()
    s += '#'
    q = []
    if len(s) >= 2 and s[0] != s[1]:
        q.append(s[0])
    for i in range(1, len(s)):
        if i + 1 < len(s) and s[i - 1] != s[i] != s[i + 1]:
            q.append(s[i])
    q.sort()
    print(''.join(q))


n = int(input())
for _ in range(n):
    s = input()
    i = 0
    q = []
    while i < len(s):
        a = 1
        while i + 1 < len(s) and s[i] == s[i + 1]:
            i += 1
            a += 1
        if a % 2 != 0:
            q.append(s[i])
        i += 1
    q = list(set(q))
    print(''.join(q))


n = int(input())
for _ in range(n):
    s = input()
    i = 0
    q = []
    while i < len(s):
        a = 1
        while i + 1 < len(s) and s[i] == s[i + 1]:
            i += 1
            a += 1
        if a % 2 != 0:
            q.append(s[i])
        i += 1
    q.sort()
    q = list(set(q))
    print(''.join(q))


n = int(input())
for _ in range(n):
    s = input()
    s += '#'
    q = []
    if len(s) >= 2 and s[0] != s[1]:
        q.append(s[0])
    for i in range(1, len(s)):
        if i + 1 < len(s) and s[i - 1] != s[i] != s[i + 1]:
            q.append(s[i])
    q.sort()
    print(' '.join(q))


n = int(input())
for _ in range(n):
    s = input()
    s += '#'
    q = []
    if len(s) >= 2 and s[0] != s[1]:
        q.append(s[0])
    for i in range(1, len(s)):
        if i + 1 < len(s) and s[i - 1] != s[i] != s[i + 1]:
            q.append(s[i])
    q = list(set(q))
    q.sort()
    print(''.join(q))