// C++ Program to shuffle a given array
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

// A utility function to swap to integers
void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

// A utility function to print an array
void printArray(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

// A function to generate a random
// permutation of arr[]
void randomize(int arr[], int n)
{
    // Use a different seed value so that
    // we don't get same result each time
    // we run this program
    srand(time(NULL));

    // Start from the last element and swap
    // one by one. We don't need to run for
    // the first element that's why i > 0
    for (int i = n - 1; i > 0; i--)
    {
        // Pick a random index from 0 to i
        int j = rand() % (i + 1);

        // Swap arr[i] with the element
        // at random index
        swap(&arr[i], &arr[j]);
    }
}

// Driver Code
int main()
{
    int test;
    cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }
        long long int z=300;
        while (z--)
        {
            vector<int> v;
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                v.push_back(i - arr[i]);
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n - 1; i++)
            {
                if (v[i] != v[i + 1])
                {
                    cnt++;
                }
            }
            if (cnt + 1 == n)
            {
                printArray(arr, n);
                break;
            }
            else
            {
                randomize(arr, n);
            }
        }
    }

    return 0;
}

// This code is contributed by
// rathbhupendra


#include <bits/stdc++.h>

using namespace std;

void printArray(int arr[], int n)
{
    for (int i = n-1; i >= 0; i--)
        cout << arr[i] << " ";
    cout << "\n";
}

int main()
{
    int test;
    cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }

        sort(arr,arr+n);

        printArray(arr,n);
    }

    return 0;
}


// C++ Program to shuffle a given array
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

// A utility function to swap to integers
void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

// A utility function to print an array
void printArray(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

// A function to generate a random
// permutation of arr[]
void randomize(int arr[], int n)
{
    // Use a different seed value so that
    // we don't get same result each time
    // we run this program
    srand(time(NULL));

    // Start from the last element and swap
    // one by one. We don't need to run for
    // the first element that's why i > 0
    for (int i = n - 1; i > 0; i--)
    {
        // Pick a random index from 0 to i
        int j = rand() % (i + 1);

        // Swap arr[i] with the element
        // at random index
        swap(&arr[i], &arr[j]);
    }
}

// Driver Code
int main()
{
    int test;
    cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }

        while (1)
        {
            vector<int> v;
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                v.push_back(i - arr[i]);
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n - 1; i++)
            {
                if (v[i] != v[i + 1])
                {
                    cnt++;
                }
            }
            if (cnt + 1 == n)
            {
                printArray(arr, n);
                break;
            }
            else
            {
                randomize(arr, n);
            }
        }
    }

    return 0;
}

// This code is contributed by
// rathbhupendra


#include <bits/stdc++.h>

using namespace std;

void printArray(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

int main()
{
    int test;
    cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }

        sort(arr,arr+n);
        reverse(arr[0],arr[n]);
        printArray(arr,n);
    }

    return 0;
}


// C++ Program to shuffle a given array
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

// A utility function to swap to integers
void swap(int *a, int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}

// A utility function to print an array
void printArray(int arr[], int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << "\n";
}

// A function to generate a random
// permutation of arr[]
void randomize(int arr[], int n)
{
    // Use a different seed value so that
    // we don't get same result each time
    // we run this program
    srand(time(NULL));

    // Start from the last element and swap
    // one by one. We don't need to run for
    // the first element that's why i > 0
    for (int i = n - 1; i > 0; i--)
    {
        // Pick a random index from 0 to i
        int j = rand() % (i + 1);

        // Swap arr[i] with the element
        // at random index
        swap(&arr[i], &arr[j]);
    }
}

// Driver Code
int main()
{
    int test;
    cin >> test;
    while (test--)
    {
        int n;
        cin >> n;
        int arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
        }
        long long int z=3000;
        while (z--)
        {
            vector<int> v;
            int cnt = 0;
            for (int i = 0; i < n; i++)
            {
                v.push_back(i - arr[i]);
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n - 1; i++)
            {
                if (v[i] != v[i + 1])
                {
                    cnt++;
                }
            }
            if (cnt + 1 == n)
            {
                printArray(arr, n);
                break;
            }
            else
            {
                randomize(arr, n);
            }
        }
    }

    return 0;
}

// This code is contributed by
// rathbhupendra


#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define i64 int64_t
#define fi first
#define se second
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int q;cin>>q;
	while(q--)
	{
		int n;cin>>n;vector<int>a(n);
		F(i,n)cin>>a[i];
		sort(a.begin(),a.end(),greater<int>());
		for(auto i:a)
			cout<<i<<" ";
		cout<<endl;
	}
}


#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define i64 int64_t
#define fi first
#define se second
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int q;cin>>q;
	while(q--)
	{
		int n;cin>>n;vector<int>a(n);
		F(i,n)cin>>a[i];
		sort(a.begin(),a.end());
		for(auto i:a)
			cout<<i<<" ";
		cout<<endl;
	}
}


#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define i64 int64_t
#define fi first
#define se second
using namespace std;
int ans(int i)
{
	if(i<0)
		return(-i);
	return i;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;cin>>n;
		vector<int>a(n);F(i,n)cin>>a[i];
		F(i,n)
		{
			int tmp=i-a[i];
			for(int j=i+1;j<n;j++)
			{
				int tmp1=j-a[j];
				if(ans(tmp)==ans(tmp1))
					swap(a[i],a[j]);
			}
		}
		F(i,n)
		{
			int tmp=i-a[i];
			for(int j=i+1;j<n;j++)
			{
				int tmp1=j-a[j];
				if(ans(tmp)==ans(tmp1))
					swap(a[i],a[j]);
			}
		}
		for(auto i:a)
			cout<<i<<" ";
		cout<<endl;
	}
}


#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define i64 int64_t
#define fi first
#define se second
using namespace std;
int ans(int i)
{
	if(i<0)
		return(-i);
	return i;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;cin>>n;
		vector<int>a(n);F(i,n)cin>>a[i];
		F(i,n)
		{
			int tmp=i-a[i];
			for(int j=i+1;j<n;j++)
			{
				int tmp1=j-a[j];
				if(tmp==tmp1)
					swap(a[i],a[j]);
			}
		}
		for(auto i:a)
			cout<<i<<" ";
		cout<<endl;
	}
}


#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define i64 int64_t
#define fi first
#define se second
using namespace std;
int ans(int i)
{
	if(i<0)
		return(-i);
	return i;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n;cin>>n;
		vector<int>a(n);F(i,n)cin>>a[i];
		F(i,n)
		{
			int tmp=i-a[i];
			for(int j=i+1;j<n;j++)
			{
				int tmp1=j-a[j];
				if(ans(tmp)==ans(tmp1))
					swap(a[i],a[j]);
			}
		}
		for(auto i:a)
			cout<<i<<" ";
		cout<<endl;
	}
}


// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
// "Works like magic, but at cost".
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int>e;
        vector<int>o;
        for(ll i=0;i<n;i++){
            if(a[i]%2==0) e.push_back(a[i]);
            else o.push_back(a[i]);
        }
        sort(e.begin(),e.end());
        sort(o.begin(),o.end());
        for(ll i=0;i<e.size();i++){
            cout<<e[i]<<" ";
        }
        for(ll i=0;i<o.size();i++){
            cout<<o[i]<<" ";
        }

        cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define cases ll t;cin>>t;while(t--)
#define md 1000000007
int main() {
    fast
    cases{
        ll n;
        cin>>n;
        ll ar[n];
        for(int i=0;i<n;i++)
            cin>>ar[i];
        sort(ar,ar+n);
        for(int i=n-1;i>=0;i--)
            cout<<ar[i]<<" ";
        cout<<endl;
    }
    return 0;
}


// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
// "Works like magic, but at cost".
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int>e;
        vector<int>o;
        for(ll i=0;i<n;i++){
            if(a[i]%2==0) e.push_back(a[i]);
            else o.push_back(a[i]);
        }
        sort(e.begin(),e.end(),greater<int>());
        sort(o.begin(),o.end(),greater<int>());
        for(ll i=0;i<e.size();i++){
            cout<<e[i]<<" ";
        }
        for(ll i=0;i<o.size();i++){
            cout<<o[i]<<" ";
        }

        cout<<"\n";
    }
}


// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
// "Works like magic, but at cost".
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n,m,even=0,odd=0;
        cin>>n;
        ll a[n];
        vector<int>e;
        vector<int>o;
        for(ll i=0;i<n;i++){
            cin>>a[i];
            if(a[i]%2==0) e.push_back(a[i]);
            else o.push_back(a[i]);
        }
        sort(e.begin(),e.end());
        sort(o.begin(),o.end());
        for(ll i=o.size()-1;i>=0;i--){
            cout<<o[i]<<" ";
        }
        for(ll i=e.size()-1;i>=0;i--){
            cout<<e[i]<<" ";
        }
        cout<<"\n";
    }
}


// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
// "Works like magic, but at cost".
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int>e;
        vector<int>o;
        vector<int>f;
        for(ll i=0;i<n;i++){
            if(a[i]%2==0) e.push_back(a[i]);
            else o.push_back(a[i]);
        }
        sort(e.begin(),e.end());
        sort(o.begin(),o.end());
        for(ll i=o.size()-1;i>=0;i--){
            f.push_back(o[i]);
        }
        for(ll i=e.size()-1;i>=0;i--){
          f.push_back(e[i]);
        }
        for(ll i=0;i<f.size();i++){
            cout<<f[i]<<" ";
        }
        cout<<"\n";
    }
}


// "It's impossible" said Pride.
// "It's risky" said Experience.
// "It's pointless" said Reason.
// "Give it a try" whispered the heart".
// "Works like magic, but at cost".
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        vector<int>e;
        vector<int>o;
        for(ll i=0;i<n;i++){
            if(a[i]%2==0) e.push_back(a[i]);
            else o.push_back(a[i]);
        }
        sort(e.begin(),e.end(),greater<int>());
        sort(o.begin(),o.end(),greater<int>());
        for(ll i=0;i<o.size();i++){
            cout<<o[i]<<" ";
        }
        for(ll i=0;i<e.size();i++){
            cout<<e[i]<<" ";
        }
        cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namestead.std
int main{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i];
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i];
        }
        cout<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i];
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i];
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i];
        }
        cout<<" "<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n],i;
        for (i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr, arr + n, greater<int>());
         for (i=0;i<n;i++){
            cout<<arr[i]<<" ";
        }
        cout<<endl;
    }

}


#include<bits/stdc++.h>

using namespace std;

int arr[100];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i= 0;i<n;++i)cin>>arr[i];
        sort(arr,arr+n,greater<int>());
    }
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'

bool is_sorted(const vector<int>& vc)
{
	for(int j = 0;j<vc.size();++j)
	{
		for(int i=0;i<j;++i)
		{
			if(j-vc[j]==i-vc[i])return false;
		}
	}
	return true;
}

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
   	int n;
   	cin>>n;
   	vector<int> vc(n);
   	for(int i=0;i<n;++i)cin>>vc[i];
   	while(!is_sorted(vc))
   	{
   	  random_shuffle(vc.begin(),vc.end());
	}
	for(int i=0;i<n;++i)cout<<vc[i]<<' ';
	cout<<en;
   }

}


#include<bits/stdc++.h>

using namespace std;

int arr[100];

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i= 0;i<n;++i)cin>>arr[i];
        sort(arr,arr+n,greater<int>());
        for(int i = 0;i<n;++i)cout<<arr[i]<<" ";
        cout<<'\n';
    }
}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'

bool is_sorted(const vector<int>& vc)
{
	for(int j = 0;j<vc.size();++j)
	{
		for(int i=0;i<j;++i)
		{
			if(j-vc[j]==i-vc[i])return false;
		}
	}
	return true;
}

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
   	int n;
   	cin>>n;
   	vector<int> vc(n);
   	for(int i=0;i<n;++i)cin>>vc[i];
   	while(!is_sorted(vc))
   	{
   	  shuffle(vc.begin(),vc.end(),default_random_engine(seed));
	}
	for(int i=0;i<n;++i)cout<<vc[i]<<' ';
	cout<<en;
   }

}


#include<bits/stdc++.h>

using namespace std;

#define en '\n'

bool is_sorted(const vector<int>& vc)
{
	for(int j = 0;j<vc.size();++j)
	{
		for(int i=0;i<j;++i)
		{
			if(j-vc[j]==i-vc[i])return false;
		}
	}
	return true;
}

int main()
{
   int t;
   cin>>t;
   while(t--)
   {
   	int n;
   	cin>>n;
   	vector<int> vc(n);
   	for(int i=0;i<n;++i)cin>>vc[i];
   	while(!is_sorted(vc))
   	{
   	  shuffle(vc.begin(),vc.end(),default_random_engine(fseek));
	}
	for(int i=0;i<n;++i)cout<<vc[i]<<' ';
	cout<<en;
   }

}


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

void sync()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	sync();
	ll t,n;cin>>t;
	while(t--)
	{
	    cin>>n;
	    ll a[n];
	    for(ll i=1; i<=n; i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n,greater<int>());
	    for(ll i=1; i<=n; i++)
	    {
	        cout<<a[i];
	    }
	}
	return 0;
}


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

void sync()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	sync();
	ll t,n;cin>>t;
	while(t--)
	{
	    cin>>n;
	    ll a[n];
	    for(ll i=1; i<=n; i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n,greater<int>());
	    for(ll i=1; i<=n; i++)
	    {
	        cout<<a[i]<<" ";
	    }
	    cout<<endl;
	}
	return 0;
}


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

void sync()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	sync();
	ll t,n;cin>>t;
	while(t--)
	{
	    cin>>n;
	    ll a[n];
	    for(ll i=0; i<n; i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n,greater<int>());
	    for(ll i=0; i<n; i++)
	    {
	        cout<<a[i]<<" ";
	    }
	    cout<<endl;
	}
	return 0;
}


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

void sync()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	sync();
	ll t,n;cin>>t;
	while(t--)
	{
	    cin>>n;
	    ll a[n];
	    for(ll i=1; i<=n; i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n,greater<int>());
	    for(ll i=1; i<=n; i++)
	    {
	        cout<<a[i];
	    }
	    cout<<endl;
	}
	return 0;
}


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

void sync()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	sync();
	ll t,n;cin>>t;
	while(t--)
	{
	    cin>>n;
	    ll a[n];
	    for(ll i=1; i<=n; i++)
	    {
	        cin>>a[i];
	    }
	    sort(a,a+n,greater<int>());
	    for(ll i=1; i<=n; i++)
	    {
	        cout>>a[i];
	    }
	}
	return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

            sort(a,a+n);

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
           {
               if((j-a[j])!=(i-a[i]))
                swap(a[i],a[j]);
           }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
           {
               if((j-a[j])!=(i-a[i]))
                swap(a[i],a[j]);
           }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

            //sort(a,a+n);

        for(int i=0; i<n-1; i++)
        {
            if(((i+1)-a[i+1]) == (i-a[i]))
                continue;
            else
            {
                swap(a[i],a[i+1]);
            }

        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((j-a[j])!=(i-a[i]))
                    continue;
                else
                {
                    swap(a[i],a[j]);
                }
            }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((i-j) != (a[j]-a[i]))
                swap(a[i],a[j]);
            }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

            //sort(a,a+n);

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((a[j]-j)==(a[i]-i))
                    continue;
                else
                {
                    swap(a[i],a[j]);
                }
            }

        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        sort(a,a+n);

        for(int i=n-1; i>=0; i--)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n-1; i++)
        {
           if((i+1-a[i+1]!=(a[i]-a[i])))
            swap(a[i+1],a[i]);
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((a[i]-a[j]) != (i-j))
                swap(a[i],a[j]);
            }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

            //sort(a,a+n);

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((a[j]-j)==(a[i]-i))
                    continue;
                else
                {
                    swap(a[i],a[j]);
                    break;
                }
            }

        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


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

/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);

///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    while(t--)
    {

        int n;

        cin >> n;

        int a[n+1]={0};

        for(int i=0; i<n; i++)
            cin >> a[i];

        for(int i=0; i<n; i++)
        {
            for(int j=i+1; j<n; j++)
            {
                if((j-i)!=(a[j]-a[i]))
                   swap(a[i],a[j]);
                else
                {
                    continue;

                }
            }
        }

        for(int i=0; i<n; i++)
            cout << a[i] << " ";

        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101], b[101];

int c(){
   map<ll,ll>w;
   int ok = 1;
   for(ll i = 1;i <= n;i++){
       if(w[i - b[i]] == 0)w[i - b[i]] = 1;
       else ok = 0;
   }return ok;
}

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        for(ll i = 1;i <= n;i++){cin >> a[i];b[i] = a[i];}
        map<ll,ll>m;
            for(ll i = 1;i <= n;i++){
                if(m[i - b[i]] == 0)m[i - b[i]] = 1;
                else{
                    for(ll j = 1;j <= n;j++){
                        m[j - b[j]] = 0;
                        if(m[j - b[i]] == 0 && m[i - b[j]] == 0){
                            ll t = b[i];
                            b[i] = b[j];
                            b[j] = t;
                            m[i - b[i]] = 1, m[j - b[j]] = 1;
                            break;
                        }else m[j - b[j]] = 1;
                    }
                }
            }
        for(ll i = 1;i <= n;i++)cout << b[i] << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101];

ll c(){
    ll ok = 1;
    map<ll,ll>m;
    for(ll i = 1;i <= n;i++){
        if(m[i - a[i]] == 0)m[i - a[i]] = 1;
        else{ ok = 0;break;}
    }
    return ok;
}

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        for(ll i = 1;i <= n;i++)cin >> a[i];
        if(c() == 1){
            for(ll i = 1;i <= n;i++)cout << a[i] << " ";
            cout << endl;
            continue;
        }
        do{
            if(c() == 1){
                for(ll i = 1;i <= n;i++)cout << a[i] << " ";
                cout << endl;
                break;
            }
        }while(next_permutation(a + 1, a + 1 + n));
    }
}


    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    ll t, n , a[101];

    ll c(){
        ll ok = 1;
        map<ll,ll>m;
        for(ll i = 1;i <= n;i++){
            if(m[i - a[i]] == 0)m[i - a[i]] = 1;
            else{ ok = 0;break;}
        }
        return ok;
    }

    int main(){
        cin >> t;
        while(t--){
            cin >> n;
            for(ll i = 1;i <= n;i++)cin >> a[i];

            do{
                if(c() == 1){
                    for(ll i = 1;i <= n;i++)cout << a[i] << " ";
                    cout << endl;
                    break;
                }
            }while(next_permutation(a + 1, a + 1 + n));
        }
    }


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101];

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        vector<ll>v;
        for(ll i = 1;i <= n;i++){cin >> a[i];v.push_back(a[i]);}
        map<ll,ll>m, u;
        for(ll i = 1;i <= n;i++){
            for(ll j = 0;j < v.size();j++){
                if(m[i - v[j]] == 0){
                    a[i] = v[j];
                    m[i - a[j]] = 1;
                    v.erase(v.begin() + j);
                    break;
                }
            }
        }for(ll i = 1;i <= n;i++)cout << a[i] << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101];

ll c(){
    ll ok = 1;
    for(ll i = 1;i < n;i++){
        for(ll j = i + 1;j <= n;j++){
            if(i - a[i] == j - a[j])ok = 0;
        }
    }return ok;
}

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        for(ll i = 1;i <= n;i++)cin >> a[i];
        if(c() == 1){
            for(ll i = 1;i <= n;i++)cout << a[i] << " ";
            cout << endl;
            continue;
        }
        do{
            if(c() == 1){
                for(ll i = 1;i <= n;i++)cout << a[i] << " ";
                cout << endl;
                break;
            }
        }while(next_permutation(a + 1, a + 1 + n));
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101], b[101];

int c(){
   map<ll,ll>w;
   int ok = 1;
   for(ll i = 1;i <= n;i++){
       if(w[i - b[i]] == 0)w[i - b[i]] = 1;
       else ok = 0;
   }return ok;
}

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        for(ll i = 1;i <= n;i++){cin >> a[i];b[i] = a[i];}
        map<ll,ll>m;
        while(c() == 0){
            for(ll i = 1;i <= n;i++){
                if(m[i - b[i]] == 0)m[i - b[i]] = 1;
                else{
                    for(ll j = 1;j <= n;j++){
                        m[j - b[j]] = 0;
                        if(m[j - b[i]] == 0 && m[i - b[j]] == 0){
                            ll t = b[i];
                            b[i] = b[j];
                            b[j] = t;
                            m[i - b[i]] = 1, m[j - b[j]] = 1;
                            break;
                        }else m[j - b[j]] = 1;
                    }
                }
            }
        }
        for(ll i = 1;i <= n;i++)cout << b[i] << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll t, n , a[101], b[101];

int c(){
   map<ll,ll>w;
   int ok = 1;
   for(ll i = 1;i <= n;i++){
       if(w[i - b[i]] == 0)w[i - b[i]] = 1;
       else ok = 0;
   }return ok;
}

int main(){
    cin >> t;
    while(t--){
        cin >> n;
        for(ll i = 1;i <= n;i++){cin >> a[i];b[i] = a[i];}
        map<ll,ll>m;
        while(c() == 0){
            for(ll i = 1;i <= n;i++){
                if(m[i - b[i]] == 0)m[i - b[i]] = 1;
                else{
                    for(ll j = 1;j <= n;j++){
                        m[j - b[j]] = 0;
                        if(m[j - b[i]] == 0 && m[i - b[j]] == 0){
                            ll t = b[i];
                            b[i] = b[j];
                            b[j] = t;
                            m[i - b[i]] = 1, m[j - b[j]] = 1;
                            break;
                        }else m[j - b[j]] = 1;
                    }
                }
            }m.clear();
        }
        for(ll i = 1;i <= n;i++)cout << b[i] << " ";
        cout << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int x,int y){
	return x>y;
}
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		int a[n+1];
		for(int k=1; k<=n; k++)
			cin>>a[k];
		sort(a+1,a+1+n,comp);
		for(int k=1; k<=n; k++)
			{
				cout<<a[k]<<' ';
			}
			cout<<endl;
	//a.clear(a+1,n+1);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int x,int y){
  return x>y;
}
int main(){
int t,n
cin>>t;
while(t--){
cin>>n;
int a[n+1];
 sort(a+1,a+n+1,comp);
for(int k=1; k<=n;k++)
    cout<<a[k]<<" ";
cout<<endl;
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int x,int y){
	return x>y;
}
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		int a[n+1];
		sort(a+1,a+1+n);
		for(int k=1; k<=n; k++)
			{
				cout<<a[k];
			}
			cout<<endl;

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool comp(int x,int y){
	return x>y;
}
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		int a[n+1];
		sort(a+1,a+1+n);
		for(int k=1; k<=n; k++)
			{
				cout<<a[k]<<' ';
			}
			cout<<endl;
	//a.clear(a+1,n+1);
	}

	return 0;
}


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

int main(){
	int t,n;
	cin>>t;
	while(t--)
	{
		cin>>n;
		int a[n+1];
		for(int k=1; k<=n; k++)
			cin>>a[k];
		for(int k=1; k<=n; k++)
			for(int i=1; i<=n; i++)
			if(a[i]-i==a[k]-k)
				swap(a[k],a[i]);
		for(int k=1; k<=n; k++)
			cout<<a[k]<<' ';
			cout<<endl;

	}

	return 0;
}


/*----------------*/
/*  ^_HAR HAR MAHADEV_^
       |Om namah shivaya|
*/
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include<boost/multiprecision/cpp_int.hpp>
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fs(i,a,b,step) for(int i=a;i<b;i+=step)
#define frs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define pf push_front
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define br "\n"
//using namespace boost::multiprecision;
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

ll findS(ll s) {
    return (sqrtl(8*s + 1) - 1)/2;
}
ll factorial(ll n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
bool prime(ll a) {
    if(a==1)return false;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return false;
    for(ll i=5; i<=sqrt(a); i+=6)
        if(a%i==0 || a%(i+2)==0)
            return false;
    return true;
}
ll power(ll x,ll y) {
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k) {
    ll C[k+1];
    C[0] = 1;

    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r) {
    return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node) {
    visited[current_node]=true;
    for(ll nxt_node : v[current_node]) {
        if(visited[nxt_node]==false) {
            dfs(v , visited, nxt_node);
        }
    }
    return;
}
void shuffle(int a[], int n)
{
    for (int i = 0; i < n; i++)
        swap(a[i], a[rand() % n]);
}
void solve(){

    int n;
    cin >> n ;
    int a[n] ;
    f(i,0,n){
        cin >> a[i] ;
    }
    if(n == 1){
        cout << a[0] << "\n";
        return ;
    }
    sort(a,a+n,greater<int>()) ;
    f(i,0,n){
        f(j,i+1,n){
            if(a[j] - j == a[i] - i){
                swap(a[j],a[j-1]);
            }
        }
    }
    f(i,0,n)cout << a[i] << " ";
    cout << br ;
}
int main(){
    srand(time(0));
   int t = 1;
   cin >> t;
   while(t--){
       solve();
   }
   return 0;
}


/*----------------*/
/*  ^_HAR HAR MAHADEV_^
       |Om namah shivaya|
*/
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include<boost/multiprecision/cpp_int.hpp>
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fs(i,a,b,step) for(int i=a;i<b;i+=step)
#define frs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define pf push_front
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define br "\n"
//using namespace boost::multiprecision;
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

ll findS(ll s) {
    return (sqrtl(8*s + 1) - 1)/2;
}
ll factorial(ll n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
bool prime(ll a) {
    if(a==1)return false;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return false;
    for(ll i=5; i<=sqrt(a); i+=6)
        if(a%i==0 || a%(i+2)==0)
            return false;
    return true;
}
ll power(ll x,ll y) {
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k) {
    ll C[k+1];
    C[0] = 1;

    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r) {
    return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node) {
    visited[current_node]=true;
    for(ll nxt_node : v[current_node]) {
        if(visited[nxt_node]==false) {
            dfs(v , visited, nxt_node);
        }
    }
    return;
}
void shuffle(int a[], int n)
{
    for (int i = 0; i < n; i++)
        swap(a[i], a[rand() % n]);
}
void solve(){

    int n;
    cin >> n ;
    int a[n] ;
    f(i,0,n){
        cin >> a[i] ;
    }
    bool ok = false ;
    f(i,0,n){
        f(j,i+1,n){
            if((j - a[j]) == (i - a[j])){
                swap(a[i],a[rand()%n]) ;
            }
        }
    }
    f(i,0,n){
        f(j,i+1,n){
            if((j - a[j]) == (i - a[j])){
                swap(a[i],a[rand()%n]) ;
            }
        }
    }
    f(i,0,n){
        f(j,i+1,n){
            if((j - a[j]) == (i - a[j])){
                swap(a[i],a[rand()%n]) ;
            }
        }
    }
    int p = 0 , l = 0 ;
    f(i,0,n)cout << a[i] << " ";
    cout << br ;
}
int main(){
    srand(time(0));
   int t = 1;
   cin >> t;
   while(t--){
       solve();
   }
   return 0;
}


/*----------------*/
/*  ^_HAR HAR MAHADEV_^
       |Om namah shivaya|
*/
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include<boost/multiprecision/cpp_int.hpp>
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fs(i,a,b,step) for(int i=a;i<b;i+=step)
#define frs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define pf push_front
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define br "\n"
//using namespace boost::multiprecision;
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

ll findS(ll s) {
    return (sqrtl(8*s + 1) - 1)/2;
}
ll factorial(ll n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
bool prime(ll a) {
    if(a==1)return false;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return false;
    for(ll i=5; i<=sqrt(a); i+=6)
        if(a%i==0 || a%(i+2)==0)
            return false;
    return true;
}
ll power(ll x,ll y) {
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k) {
    ll C[k+1];
    C[0] = 1;

    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r) {
    return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node) {
    visited[current_node]=true;
    for(ll nxt_node : v[current_node]) {
        if(visited[nxt_node]==false) {
            dfs(v , visited, nxt_node);
        }
    }
    return;
}
void solve(){
    int n;
    cin >> n ;
    int a[n] ;
    f(i,0,n){
        cin >> a[i] ;
    }
    sort(a,a+n);
    int p = 0 , l = 0 ;
    f(i,0,n){
        if(i%2 == 0){
            cout << a[p] << " ";
        }
        else
        {
            cout << a[n-++p] << " ";
        }
    }
    cout << br ;
}
int main(){
   int t = 1;
   cin >> t;
   while(t--){
       solve();
   }
   return 0;
}


/*----------------*/
/*  ^_HAR HAR MAHADEV_^
       |Om namah shivaya|
*/
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include<boost/multiprecision/cpp_int.hpp>
#define mod 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fs(i,a,b,step) for(int i=a;i<b;i+=step)
#define frs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define pf push_front
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define br "\n"
//using namespace boost::multiprecision;
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

ll findS(ll s) {
    return (sqrtl(8*s + 1) - 1)/2;
}
ll factorial(ll n)
{
    if (n == 0)
    return 1;
    return n * factorial(n - 1);
}
bool prime(ll a) {
    if(a==1)return false;
    if(a==2 || a==3)return true;
    if(a%2==0 ||a%3==0)return false;
    for(ll i=5; i<=sqrt(a); i+=6)
        if(a%i==0 || a%(i+2)==0)
            return false;
    return true;
}
ll power(ll x,ll y) {
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % mod;
    p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}
ll nCr(ll n,ll k) {
    ll C[k+1];
    C[0] = 1;

    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j] + C[j-1])%(ll)(1e9 + 7);
    }
    return C[k];
}
ll LOGN(ll n , ll r) {
    return (n > r-1) ? (1 + LOGN(n / r , r)) : 0 ;
}
void dfs(vector<ll> v[], bool visited[], ll current_node) {
    visited[current_node]=true;
    for(ll nxt_node : v[current_node]) {
        if(visited[nxt_node]==false) {
            dfs(v , visited, nxt_node);
        }
    }
    return;
}
void shuffle(int a[], int n)
{
    for (int i = 0; i < n; i++)
        swap(a[i], a[rand() % n]);
}
void solve(){

    int n;
    cin >> n ;
    int a[n] ;
    f(i,0,n){
        cin >> a[i] ;
    }
    if(n == 1){
        cout << a[0] << "\n";
        return ;
    }
    sort(a,a+n) ;
    bool ok = false ;
    int  p = 0 ;
    f(i,0,n/2){
        cout << a[p] << " " ;
        p+=2 ;
    }
    p =  0;
    f(i,0,n - n/2){
        cout << a[p+1] << " " ;
        p+=2 ;
    }
    cout << br ;
}
int main(){
    srand(time(0));
   int t = 1;
   cin >> t;
   while(t--){
       solve();
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        for(i=0;i<n;++i)
        {
            cin>>g[i];
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(auto t:g)
            cout <<t<<" ";
        cout<<"\n";
    }while(--t);
    return 0;
}


#include <iostream>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        for(i=0;i<n:++i)
        {
            cin>>g[i];
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(auto t:g)
            cout <<t<<" ";
    }while(--t);
    return 0;
}


#include <iostream>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        for(i=0;i<n,++i)
        {
            cin>>g[i];
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(auto t:g)
            cout <<t<<" ";
    }while(--t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        for(i=0;i<n;++i)
        {
            cin>>g[i];
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(auto t:g)
            cout <<t<<" ";
    }while(--t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        for(i=0;i<n,++i)
        {
            cin>>g[i];
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(auto t:g)
            cout <<t<<" ";
    }while(--t);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int n,i,j,k,l,temp;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>j;
            g.push_back(j);
        }
        for(i=0;i<n-1;i++)
        {
            k=i-g[i];
            for(j=i+1;j<n;j++)
            {
                if(k==(j-g[j]))
                {
                    temp = g[i];
                    g[i] = g[j];
                    g[j] = temp;
                    i=0;
                }
            }
        }
        for(int i:g)
            cout<<i<<" ";
        cout<<"\n";
    }while(--t);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        vi d;
        int n,i,j,k,l,temp;
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>j;
            g.push_back(j);
        }
        for(i=0;i<n-1;i++)
        {
            k=i-g[i];
            for(j=i+1;j<n;j++)
            {
                if(k==(j-g[j]))
                {
                    temp = g[i];
                    g[i] = g[j];
                    g[j] = temp;
                    i=0;
                }
            }
        }
        for(i=0;i<n;i++)
        {
            j=i-g[i];
            d.push_back(j);
        }
        for(i=0;i<n-1;i++)
        {
            int mi=d[i];
            k=i;
            for(j=i+1;j<n;j++)
            {
                if(mi>d[j])
                {
                    mi=d[i];
                    k=j;
                }
            }
            temp = d[i];
            d[i]=d[k];
            d[k]=temp;
            temp=g[i];
            g[i]=g[k];
            g[k]=temp;
        }
        for(int i:g)
            cout<<i<<" ";
        cout<<"\n";
    }while(--t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    do{
        vi g;
        int i,j,n;
        cin>>n;
        for(i=0;i<n;++i)
        {
            cin>>j;
            g.push_back(j);
        }
        sort(g.begin(),g.end());
        reverse(g.begin(),g.end());
        for(int t:g)
            cout <<t<<" ";
        cout<<"\n";
    }while(--t);
    return 0;
}


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

bool cmp(int a,int b)
{
    return a >= b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a;
        a.resize(n);
        for(int &x : a) cin>>x;
        sort(a.begin(),a.end(),cmp);
        for(int x : a) cout<<x<<' ';
        cout<<'\n';
    }
}


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

bool cmp(int a,int b)
{
    return a >= b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a;
        a.resize(n);
        for(auto &x : a) cin>>x;
        sort(a.begin(),a.end(),cmp);
        for(auto &x : a) cout<<x;
        cout<<'\n';
    }
}


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

bool cmp(int a,int b)
{
    return a > b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a;
        a.resize(n);
        for(int &x : a) cin>>x;
        sort(a.begin(),a.end(),cmp);
        for(int x : a) cout<<x<<' ';
        cout<<'\n';
    }
}


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

bool cmp(int a,int b)
{
    return a > b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a;
        a.resize(n);
        for(auto &x : a) cin>>x;
        sort(a.begin(),a.end(),cmp;
        for(auto &x : a) cout>>x;
        cout<<'\n';
    }
}


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

bool cmp(int a,int b)
{
    return a > b;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a;
        a.resize(n);
        for(auto &x : a) cin>>x;
        sort(a.begin(),a.end(),cmp());
        for(auto &x : a) cout>>x;
        cout<<'\n';
    }
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    vi a(n);int s=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
        s+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int q;
    cin>>q;int k;
    map<int,int>mp;
    while(q--)
    {
        cin>>k;
        if(k>=n-1)
        {
            cout<<s-a[0]<<" ";

        }
        else if(mp.find(k)!=mp.end())
        {
            cout<<mp[k]<<" ";
        }
        else
        {
        int ans=0;
        int z=1;
        for(int i=1;i<n;i++)
        {
            if(!(i%k))
            {
                ans+=z*a[i];
                z++;
            }
            else
                ans+=z*a[i];
        }
        mp.insert(m1(k,ans));
        cout<<ans<<" ";
        }
    }
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }

    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    vi a(n);int s=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
        s+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int pre[n]={0};
    pre[0]=a[0];
    for(int i=1;i<n;i++)
        pre[i]=pre[i-1]+a[i];
    int q;
    cin>>q;int k;
    map<int,int>mp;
    while(q--)
    {
        cin>>k;
        if(k>=n-1)
        {
            cout<<s-a[0]<<" ";

        }
        else if(mp.find(k)!=mp.end())
        {
            cout<<mp[k]<<" ";
        }
        else
        {
        int ans=0;
            int z=1;int p=1;
        for(int i=1;i<n;i+=p)
        {
            ans+=z*(pre[min(n-1,i+p*k-1)]-(i>=1?pre[i-1]:0));
            z++;
            p=p*k;
        }
        mp.insert(m1(k,ans));
        cout<<ans<<" ";
        }
    }
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }

    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    vi a(n);int s=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
        s+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int pre[n]={0};
    pre[0]=a[0];
    for(int i=1;i<n;i++)
        pre[i]=pre[i-1]+a[i];
    int q;
    cin>>q;int k;
    map<int,int>mp;
    while(q--)
    {
        cin>>k;
        if(k>=n-1)
        {
            cout<<s-a[0]<<" ";

        }
        else if(mp.find(k)!=mp.end())
        {
            cout<<mp[k]<<" ";
        }
        else
        {
        int ans=0;
        int z=1;
        for(int i=0;i<n;i+=k)
        {
            ans+=z*(pre[min(n-1,i+k-1)]-(i>=1?pre[i-1]:0));
            ans-=a[i];
            z++;
        }
        mp.insert(m1(k,ans));
        cout<<ans<<" ";
        }
    }
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }

    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    vi a(n);int s=0;
    for(int i=0;i<n;i++)
    {cin>>a[i];
        s+=a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int q;
    cin>>q;int k;
    map<int,int>mp;
    while(q--)
    {
        cin>>k;
        if(k>=n-1)
        {
            cout<<s-a[0]<<" ";
            continue;
        }
        if(mp.find(k)!=mp.end())
        {
            cout<<mp[k]<<" ";
            continue;
        }
        int ans=0;
        int z=1;
        for(int i=1;i<n;i++)
        {
            if(!(i%k))
            {
                ans+=z*a[i];
                z++;
            }
            else
                ans+=z*a[i];
        }
        mp[k]=ans;
        cout<<ans<<" ";
    }
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
#define clr(k,v) memset(k,v,sizeof(k))
#define eps 1e-9
#define pi acos(-1)
#define INF 0x7fffffff
#define inf -INF
#define MM 12900
#define N 50
using namespace std;
typedef long long LL;
const int _max = 2e5 + 10;

struct Point{
  double x,y;
}p[5];

double dist(Point a,Point b){
   return hypot(a.x-b.x,a.y-b.y);
}

long double Area_of_overlap(Point c1,double r1,Point c2,double r2){
   double d = dist(c1,c2);
   if(r1 + r2 < d + eps)return 0;
   if(d < fabs(r1 - r2) + eps){
     double r = min(r1,r2);
     return pi*r*r;
    }
   double t1 = (d*d + r1*r1 - r2*r2)/(2*d*r1);
   double t2 = (d*d + r2*r2 - r1*r1)/(2*d*r2);
   t1 = acos(t1);
   t2 = acos(t2);
   return r1*r1*(t1-sin(2*t1)/2) + r2*r2*(t2-sin(2*t2)/2);
}

double ans1,ans2,ans3,r,R;

int main(){
#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
  while(scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&r,&p[2].x,&p[2].y,&R)!=EOF){
    double ans = Area_of_overlap(p[1],r,p[2],R);
    printf("%.12Lf\n",ans);
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
#define clr(k,v) memset(k,v,sizeof(k))
#define eps 1e-9
#define pi acos(-1)
#define INF 0x7fffffff
#define inf -INF
#define MM 12900
#define N 50
using namespace std;
typedef long long LL;
const int _max = 2e5 + 10;

struct Point{
  double x,y;
}p[5];

double dist(Point a,Point b){
   return hypot(a.x-b.x,a.y-b.y);
}

long double Area_of_overlap(Point c1,double r1,Point c2,double r2){
   //long double d = dist(c1,c2);
   long double d=sqrtl((p[1].x-p[2].x)*(p[1].x-p[2].x)+(p[1].y-p[2].y)*(p[1].y-p[2].y));
   if(r1 + r2 < d + eps)return 0;
   if(d < fabs(r1 - r2) + eps){
     double r = min(r1,r2);
     return pi*r*r;
    }
    long double t1 = (d*d + r1*r1 - r2*r2)/(2*d*r1);
    long double t2 = (d*d + r2*r2 - r1*r1)/(2*d*r2);
   t1 = acosl(t1);
   t2 = acosl(t2);
   long double ans = r1*r1*t1;ans-=r1*r1*sinl(t1)*cosl(t1);
   ans+=r2*r2*t2;ans-=r2*r2*sinl(t2)*cosl(t2);
   return ans;
   return r1*r1*(t1-sinl(t1))/2 + r2*r2*(t2-sinl(t2))/2;
}

double ans1,ans2,ans3,r,R;

int main(){
#ifndef ONLINE_JUDGE
   //freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE

  while(scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&r,&p[2].x,&p[2].y,&R)!=EOF){
    double ans = Area_of_overlap(p[1],r,p[2],R);
    printf("%.10Lf\n",ans);
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
#define clr(k,v) memset(k,v,sizeof(k))
#define eps 1e-9
#define pi acos(-1)
#define INF 0x7fffffff
#define inf -INF
#define MM 12900
#define N 50
using namespace std;
typedef long long LL;
const int _max = 2e5 + 10;

struct Point{
  double x,y;
}p[5];

double dist(Point a,Point b){
   return hypot(a.x-b.x,a.y-b.y);
}

double Area_of_overlap(Point c1,double r1,Point c2,double r2){
   double d = dist(c1,c2);
   if(r1 + r2 < d + eps)return 0;
   if(d < fabs(r1 - r2) + eps){
     double r = min(r1,r2);
     return pi*r*r;
    }
   //if(d==0)
   double x = (d*d + r1*r1 - r2*r2)/(2*d);
   double t1 = acos(x / r1);
   double t2 = acos((d - x)/r2);
   return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
}

double ans1,ans2,ans3,r,R;

int main(){
#ifndef ONLINE_JUDGE
   //freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
  while(scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&r,&p[2].x,&p[2].y,&R)!=EOF){
    double ans = Area_of_overlap(p[1],r,p[2],R);
    printf("%.10f\n",ans);
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
#define clr(k,v) memset(k,v,sizeof(k))
#define eps 1e-9
#define pi acos(-1)
#define INF 0x7fffffff
#define inf -INF
#define MM 12900
#define N 50
using namespace std;
typedef long long LL;
const int _max = 2e5 + 10;

struct Point{
  double x,y;
}p[5];

double dist(Point a,Point b){
   return hypot(a.x-b.x,a.y-b.y);
}

long double Area_of_overlap(Point c1,double r1,Point c2,double r2){
   long double d=sqrtl((p[1].x-p[2].x)*(p[1].x-p[2].x)+(p[1].y-p[2].y)*(p[1].y-p[2].y));
   if(r1 + r2 < d + eps) return 0;
   if(d < fabs(r1 - r2) + eps){
     double r = min(r1,r2);
     return pi*r*r;
   }
   long double t1 = acosl((d*d + r1*r1 - r2*r2)/(2*d*r1));
   long double t2 = acosl((d*d + r2*r2 - r1*r1)/(2*d*r2));
   long double a1 = r1*r1*(t1-sinl(2*t1)/2);
   long double a2 = r2*r2*(t2-sinl(2*t2)/2);
   return a1 + a2;;
}

double ans1,ans2,ans3,r,R;

int main(){
#ifndef ONLINE_JUDGE
   //freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE

  while(scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&r,&p[2].x,&p[2].y,&R)!=EOF){
    double ans = Area_of_overlap(p[1],r,p[2],R);
    printf("%.20Lf\n",ans);
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<sstream>
#define clr(k,v) memset(k,v,sizeof(k))
#define eps 1e-9
#define pi acos(-1)
#define INF 0x7fffffff
#define inf -INF
#define MM 12900
#define N 50
using namespace std;
typedef long long LL;
const int _max = 2e5 + 10;

struct Point{
  double x,y;
}p[5];

double dist(Point a,Point b){
   return hypot(a.x-b.x,a.y-b.y);
}

long double Area_of_overlap(Point c1,double r1,Point c2,double r2){
   double d = dist(c1,c2);
   if(r1 + r2 < d + eps)return 0;
   if(d < fabs(r1 - r2) + eps){
     double r = min(r1,r2);
     return pi*r*r;
    }
   long double x = (d*d + r1*r1 - r2*r2)/(2*d);
   long double t1 = acos(x / r1);
   long double t2 = acos((d - x)/r2);
   return r1*r1*(t1-sin(2*t1)/2) + r2*r2*(t2-sin(2*t2)/2);
}

double ans1,ans2,ans3,r,R;

int main(){
#ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
#endif // ONLINE_JUDGE
  while(scanf("%lf%lf%lf%lf%lf%lf",&p[1].x,&p[1].y,&r,&p[2].x,&p[2].y,&R)!=EOF){
    double ans = Area_of_overlap(p[1],r,p[2],R);
    printf("%.12Lf\n",ans);
  }
  return 0;
}


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

typedef long double LD;

const LD ep = 1e-10, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { double xx, yy; scanf("%lf %lf", &xx, &yy); x = xx, y = yy; }
	void FastInput() {
		int a, b;
		cin >> a >> b;
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", (double)x, (double) y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r + ep) return pi*rr*rr;
	if (r+rr<=d + ep) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=(acos(x/r)-x*sqrt(r*r-x*x)/r/r)*r*r;
	LD res2=(acos(xx/rr)-xx*sqrt(rr*rr-xx*xx)/rr/rr)*rr*rr;
	return res1+res2;
}

int main() {
	//freopen("d.in", "r", stdin);
	O[1].input();

	scanf("%lf", &R[1]);
	O[2].input();

	scanf("%lf", &R[2]);
	//printf("%lf %lf\n", R[1], R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}


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

typedef long double LD;

const LD ep = 1e-12, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { double xx, yy; scanf("%lf %lf", &xx, &yy); x = xx, y = yy; }
	void FastInput() {
		int a, b;
		cin >> a >> b;
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", (double)x, (double) y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r + ep) return pi*rr*rr;
	if (r+rr<=d + ep) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=acos(x/r)*r*r-x*sqrt(r*r-x*x);
	LD res2=acos(xx/rr)*rr*rr-xx*sqrt(rr*rr-xx*xx);
	return res1+res2;
}

int main() {
	//freopen("d.in", "r", stdin);
	O[1].input();

	scanf("%lf", &R[1]);
	O[2].input();

	scanf("%lf", &R[2]);
	//printf("%lf %lf\n", R[1], R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}


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

typedef long double LD;

const LD ep = 1e-10, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { x = y = 0, scanf("%lf %lf", &x, &y); }
	void FastInput() {
		int a, b;
		scanf("%d %d", &a, &b);
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", x, y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r) return pi*rr*rr;
	if (r+rr<=d) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=acos(x/r)*r*r-x*sqrt(r*r-x*x);
	LD res2=acos(xx/rr)*rr*rr-xx*sqrt(rr*rr-xx*xx);
	return res1+res2;
}

int main() {
//	freopen("d.in", "r", stdin);
	O[1].input();
	scanf("%lf", &R[1]);
	O[2].input();
	scanf("%lf", &R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}


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

typedef long double LD;

const LD ep = 1e-10, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { double xx, yy; scanf("%lf %lf", &xx, &yy); x = xx, y = yy; }
	void FastInput() {
		int a, b;
		cin >> a >> b;
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", (double)x, (double) y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r + ep) return pi*rr*rr;
	if (r+rr<=d + ep) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=acos(x/r)*r*r-x*sqrt(r*r-x*x);
	LD res2=acos(xx/rr)*rr*rr-xx*sqrt(rr*rr-xx*xx);
	return res1+res2;
}

int main() {
	//freopen("d.in", "r", stdin);
	O[1].input();

	scanf("%lf", &R[1]);
	O[2].input();

	scanf("%lf", &R[2]);
	//printf("%lf %lf\n", R[1], R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}


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

typedef long double LD;

const LD ep = 1e-10, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { double xx, yy; scanf("%lf %lf", &xx, &yy); x = xx, y = yy; }
	void FastInput() {
		int a, b;
		cin >> a >> b;
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", (double)x, (double) y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r) return pi*rr*rr;
	if (r+rr<=d) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=acos(x/r)*r*r-x*sqrt(r*r-x*x);
	LD res2=acos(xx/rr)*rr*rr-xx*sqrt(rr*rr-xx*xx);
	return res1+res2;
}

int main() {
	//freopen("d.in", "r", stdin);
	O[1].input();

	scanf("%lf", &R[1]);
	O[2].input();

	scanf("%lf", &R[2]);
	//printf("%lf %lf\n", R[1], R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}


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

typedef long double LD;

const LD ep = 1e-8, pi = acos(-1);

struct pnt {
	LD x, y;
	pnt (LD x = 0, LD y = 0): x(x), y(y) {}
	inline pnt operator - (const pnt &a) const { return pnt(x - a.x, y - a.y); }
	inline pnt operator + (const pnt &a) const { return pnt(x + a.x, y + a.y); }
	inline pnt operator * (const LD &a) const { return pnt(x * a, y * a); }
	inline pnt operator / (const LD &a) const { return pnt(x / a, y / a); }
	inline LD operator & (const pnt &a) const { return x * a.x + y * a.y; }
	inline LD operator ^ (const pnt &a) const { return x * a.y - y * a.x; }
	inline void input() { double xx, yy; scanf("%lf %lf", &xx, &yy); x = xx, y = yy; }
	void FastInput() {
		int a, b;
		cin >> a >> b;
		x = 1.0 * a;
		y = 1.0 * b;
	}
	inline void print() { printf("%lf %lf\n", (double)x, (double) y); }
	inline bool operator < (const pnt &a) const {
		if (fabs(x - a.x) > ep) return x < a.x;
		return y < a.y;
	}
	inline bool operator == (const pnt &a) const {
		return fabs(x - a.x) < ep && fabs(y - a.y) < ep;
	}
	inline pnt Rotate(const LD &angle) {
		pnt R = pnt(sin(angle), cos(angle)), C = *this;
		return pnt(C ^ R, C & R);
	}
	inline LD dist() { return sqrt(x * x + y * y); }
	inline pnt norm() { return (*this) / dist(); }
} O[3], p[3];

double R[3];

LD dist(pnt a) {return sqrt(a.x * a.x + a.y * a.y);}

LD common_circles(pnt c, LD r, pnt cc, LD rr){
	if (r<rr){
		swap(c,cc);
		swap(r,rr);
	}
	LD d=dist(c-cc);
	if (rr+d<=r + ep) return pi*rr*rr;
	if (r+rr<=d + ep) return 0;
	LD x=(r*r-rr*rr+d*d)/(d*2);
	LD xx=d-x;
	LD res1=acos(x/r)*r*r-x*sqrt(r*r-x*x);
	LD res2=acos(xx/rr)*rr*rr-xx*sqrt(rr*rr-xx*xx);
	return res1+res2;
}

int main() {
	//freopen("d.in", "r", stdin);
	O[1].input();

	scanf("%lf", &R[1]);
	O[2].input();

	scanf("%lf", &R[2]);
	//printf("%lf %lf\n", R[1], R[2]);
	printf("%.12lf\n", (double)common_circles(O[1], R[1], O[2], R[2]));
	return 0;
}