#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cctype>

using namespace std;
typedef long long int64;
const int inf = 0x3f3f3f3f;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int> pip;
#define Eo(x) { cerr << #x << " = " << (x) << endl; }

template<typename T>
T gcd(const T& a, const T& b) {
  return a == 0 ? b : gcd(b%a,a);
}

template<typename T>
bool isprime(const T& k){
  for (T i = 2;i*i<=k;i++)if ((k%i)==0) return false;
  return true;
}

template<typename T>
T mabs(const T& x) {
  if (x>=0) return x;
  return -x;
}

#define PRIMES 0
#if PRIMES
vector<int> primes;
void factorize(int64 x, map<int64,int>& all){
  int i;
  for (i = 0;i<primes.size()&&int64(primes[i])*primes[i]<=x;i++)if (!(x%primes[i])){
    int q = 0;
    for (;!(x%primes[i]);x/=primes[i],q++);
    all[primes[i]]+=q;
  }
  assert(i<primes.size());
  if (x>1)all[x]++;
}
const int maxn = 1<<27;
char isp[maxn];
#endif

const int maxn = 1<<20;
int comp[maxn];
int getcomp(int x) {
  return comp[x] == x ? x : comp[x] = getcomp(comp[x]);
}
void merge(int x, int y) {
   x = getcomp(x);
   y = getcomp(y);
   if (x==y)return;
   if(rand()&1) comp[x]=y;
   else comp[y]=x;
}
int b[maxn];

int main(){
  int n,k,mod; cin >> n >> k >> mod;
  for (int i = 0; i < n; i++) comp[i]=i;
  for (int i = 0; i < k; i++) {
    int x,y; scanf("%d%d",&x,&y);
    x--;y--;
    merge(x,y);
  }
  map<int,int> all;
  for (int i = 0; i < n; i++) all[getcomp(i)]++;
  int cnt = 0;
  int64 res = 1;
  for (map<int,int>::const_iterator it = all.begin(); it != all.end(); ++it) {
    res = (res*it->second)%mod;
  }
  if (all.size()==1){
    puts("0");
    return 0;
  }
  for (int i = 0; i < all.size()-2; i++) {
    res = (res*n)%mod;
  }
  cout << res << endl;
  return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <cctype>

using namespace std;
typedef long long int64;
const int inf = 0x3f3f3f3f;
typedef double real;
const real eps = 1e-6;
typedef pair<int64,int> pip;
#define Eo(x) { cerr << #x << " = " << (x) << endl; }

template<typename T>
T gcd(const T& a, const T& b) {
  return a == 0 ? b : gcd(b%a,a);
}

template<typename T>
bool isprime(const T& k){
  for (T i = 2;i*i<=k;i++)if ((k%i)==0) return false;
  return true;
}

template<typename T>
T mabs(const T& x) {
  if (x>=0) return x;
  return -x;
}

#define PRIMES 0
#if PRIMES
vector<int> primes;
void factorize(int64 x, map<int64,int>& all){
  int i;
  for (i = 0;i<primes.size()&&int64(primes[i])*primes[i]<=x;i++)if (!(x%primes[i])){
    int q = 0;
    for (;!(x%primes[i]);x/=primes[i],q++);
    all[primes[i]]+=q;
  }
  assert(i<primes.size());
  if (x>1)all[x]++;
}
const int maxn = 1<<27;
char isp[maxn];
#endif

const int maxn = 1<<20;
int comp[maxn];
int getcomp(int x) {
  return comp[x] == x ? x : comp[x] = getcomp(comp[x]);
}
void merge(int x, int y) {
   x = getcomp(x);
   y = getcomp(y);
   if (x==y)return;
   if(rand()&1) comp[x]=y;
   else comp[y]=x;
}
int b[maxn];

int main(){
  int64 n,k,mod; cin >> n >> k >> mod;
  for (int i = 0; i < n; i++) comp[i]=i;
  for (int i = 0; i < k; i++) {
    int x,y; scanf("%d%d",&x,&y);
    x--;y--;
    merge(x,y);
  }
  map<int,int64> all;
  for (int i = 0; i < n; i++) all[getcomp(i)]++;
  int64 res = 1%mod;
  for (map<int,int64>::const_iterator it = all.begin(); it != all.end(); ++it) {
    res = (res*it->second)%mod;
  }
  if (all.size()==1){
    puts("0");
    return 0;
  }
  for (int i = 0; i < all.size()-2; i++) {
    res = (res*n)%mod;
  }
  cout << res << endl;
  return 0;
}


/*
一开始看成一定要A->C->B了QAQ。。。
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, k, cnt[100005];
int x, y, fa[100005];
int Getfa(int x) {
    if (fa[x] == x) return x;
    return fa[x] = Getfa(fa[x]);
}
int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++) {
        scanf("%d %d", &x, &y);
        fa[Getfa(x)] = Getfa(y);
    }
    for (int i = 1; i <= n; i ++) cnt[Getfa(i)] ++;
    ll ans = 1; int p = 0;
    for (int i = 1; i <= n; i ++) {
        if (i == fa[i]) {
            ans = ans * cnt[i] % k; p ++;
        }
    }
    if (p == 1) ans /= cnt[fa[1]];
    for (int i = 0; i < p - 2; i ++) ans = ans * n % k;
    cout << ans << endl;
    return 0;
}
/*
9 6 342597160
1 2
3 4
4 5
6 7
7 8
8 9
*/


#include<bits/stdc++.h>
using namespace std;
int n, m, k, cnt[100005];
int x[100005], y[1000005];
bool cmp(int a, int b) {
    return a > b;
}
int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 1; i <= m; i ++) {
        scanf("%d %d", &x[i], &y[i]);
        cnt[x[i]] ++; cnt[y[i]] ++;
    }
    if (n <= 2) return puts("1");
    sort(cnt, cnt + 100005, cmp);
    int ans = 0;
    if (m)
    for (int i = 0; i < m; i ++) {
        if (cnt[i] == cnt[i - 1]) ans ++;
        else break;
    } else {
        return cout << n % k << endl, 0;
    }
    cout << ans % k << endl;
}


/*
一开始看成一定要A->C->B了QAQ。。。
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, k, cnt[100005];
int x, y, fa[100005];
int Getfa(int x) {
    if (fa[x] == x) return x;
    return fa[x] = Getfa(fa[x]);
}
int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 0; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++) {
        scanf("%d %d", &x, &y);
        fa[Getfa(x)] = Getfa(y);
    }
    for (int i = 1; i <= n; i ++) cnt[Getfa(i)] ++;
    ll ans = 1; int p = 0;
    for (int i = 1; i <= n; i ++) {
        if (i == fa[i]) {
            ans = ans * cnt[i] % k; p ++;
        }
    }
    if (p == 1) ans /= n;
    for (int i = 1; i <= p - 2; i ++) ans = ans * n % k;
    cout << ans << endl;
    return 0;
}
/*
9 6 342597160
1 2
3 4
4 5
6 7
7 8
8 9
*/


/*
一开始看成一定要A->C->B了QAQ。。。
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n, m, k, cnt[100005];
int x, y, fa[100005];
int Getfa(int x) {
    if (fa[x] == x) return x;
    return fa[x] = Getfa(fa[x]);
}
int main() {
    scanf("%d %d %d", &n, &m, &k);
    for (int i = 1; i <= n; i ++) fa[i] = i;
    for (int i = 1; i <= m; i ++) {
        scanf("%d %d", &x, &y);
        fa[Getfa(x)] = Getfa(y);
    }
    for (int i = 1; i <= n; i ++) cnt[fa[i]] ++;
    ll ans = 1;
    int p = 0;
    for (int i = 1; i <= n; i ++) {
        if (i == fa[i]) {
            ans = ans * cnt[i] % k; p ++;
        }
    }
    if (p == 1) ans /= cnt[fa[1]];
    for (int i = 0; i < p - 2; i ++) ans = ans * n % k;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int Maxn=1e5+10;
typedef __int64 ll;
struct Road
{
    int x,y;
}road[Maxn];
int root[Maxn];
ll cnt[Maxn];
int n,m;
ll k;
int getRoot(int x)
{
    if(root[x]==-1)return x;
    return root[x]=getRoot(root[x]);
}
ll powMod(ll x,ll y,ll M)
{
    if(y<0)y=0;
    ll ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%M;
        x=x*x%M;
        y>>=1;
    }
    return ret;
}
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d%I64d",&n,&m,&k);
    memset(root,-1,sizeof(root));
    for(int i=1;i<=n;++i)cnt[i]=1;
    for(int i=0;i<m;++i)
    {
        scanf("%d%d",&road[i].x,&road[i].y);
        int x=getRoot(road[i].x);
        int y=getRoot(road[i].y);
        if(x==y)continue;
        root[x]=y;
        cnt[y]+=cnt[x];
        cnt[x]=0;
    }
    int num=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
        if(cnt[i])
        {
            num++;
            ans=ans*cnt[i]%k;
        }
    if(num==1)printf("%I64d\n",1%k);
    else
    {
        ll pow=powMod(n,num-2,k);
        printf("%I64d\n",ans*pow%k);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int Maxn=1e5+10;
typedef __int64 ll;
struct Road
{
    int x,y;
}road[Maxn];
int root[Maxn];
ll cnt[Maxn];
int n,m;
ll k;
int getRoot(int x)
{
    if(root[x]==-1)return x;
    return root[x]=getRoot(root[x]);
}
ll powMod(ll x,ll y,ll M)
{
    if(y<0)y=0;
    ll ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%M;
        x=x*x%M;
        y>>=1;
    }
    return ret;
}
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d%I64d",&n,&m,&k);
    memset(root,-1,sizeof(root));
    for(int i=1;i<=n;++i)cnt[i]=1;
    for(int i=0;i<m;++i)
    {
        scanf("%d%d",&road[i].x,&road[i].y);
        int x=getRoot(road[i].x);
        int y=getRoot(road[i].y);
        if(x==y)continue;
        root[x]=y;
        cnt[y]+=cnt[x];
        cnt[x]=0;
    }
    int num=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
        if(cnt[i])
        {
            num++;
            ans=ans*cnt[i]%k;
        }
    if(num==1)printf("1\n");
    else
    {
        ll pow=powMod(n,num-2,k);
        printf("%I64d\n",ans*pow%k);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int Maxn=1e5+10;
typedef __int64 ll;
struct Road
{
    int x,y;
}road[Maxn];
int root[Maxn];
ll cnt[Maxn];
int n,m;
ll k;
int getRoot(int x)
{
    if(root[x]==-1)return x;
    return root[x]=getRoot(root[x]);
}
ll powMod(ll x,ll y,ll M)
{
    if(y<0)y=0;
    ll ret=1;
    while(y)
    {
        if(y&1)ret=ret*x%M;
        x=x*x%M;
        y>>=1;
    }
    return ret;
}
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d%I64d",&n,&m,&k);
    memset(root,-1,sizeof(root));
    for(int i=1;i<=n;++i)cnt[i]=1;
    for(int i=0;i<m;++i)
    {
        scanf("%d%d",&road[i].x,&road[i].y);
        int x=getRoot(road[i].x);
        int y=getRoot(road[i].y);
        if(x==y)continue;
        root[x]=y;
        cnt[y]+=cnt[x];
        cnt[x]=0;
    }
    int num=0;
    ll ans=1;
    for(int i=1;i<=n;++i)
        if(cnt[i])
        {
            num++;
            ans=ans*cnt[i]%k;
        }
    if(num==1)printf("0\n");
    else
    {
        ll pow=powMod(n,num-2,k);
        printf("%I64d\n",ans*pow%k);
    }
    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<long long> t;
long long d[N],x,y,i,j,n,m,k;
long long o=1;

long long get(long long p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	if(t.size()>1)for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	if(t.size()==1)cout<<(o*((long double)1/n))<<"\n";else cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<long long> t;
long long o=1,d[N],x,y,i,j,n,m,k;

long long get(long long p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	if(t.size()>1)for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<long long> t;
long long o=1,d[N],x,y,i,j,n,m,k;

long long get(long long p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<int> t;
int o=1,d[N],x,y,i,j,n,m,k;

int get(int p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<long long> t;
long long o=1,d[N],x,y,i,j,n,m,k;

long long get(long long p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	if(t.size()>0){
		if(t.size()==1)o*=(1.0/n);else for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	}
	cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<int> t;
int o=1,d[N],x,y,i,j,n,m,k;

int get(int p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	if(t.size()>1)for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	cout<<o<<"\n";
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#define F first
#define S second
#define P system("PAUSE");
#define H return 0;
#define pb push_back
using namespace std;
const long long A=100000000000000LL,N=228228;

map<int,int> g;
vector<long long> t;
long long d[N],x,y,i,j,n,m,k;
long double o=1;

long long get(long long p){
	if(d[p]!=p)d[p]=get(d[p]);
	return d[p];
}

int main(){
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)d[i]=i;
	while(m--){
		scanf("%d%d",&x,&y);
		d[get(x)]=get(y);
	}
	for(i=1;i<=n;i++)d[i]=get(d[i]);
	for(i=1;i<=n;i++)if(!g[d[i]])g[d[i]]=1,t.pb(d[i]);else g[d[i]]++;
	for(i=0;i<t.size();i++)o*=g[t[i]],o%=k;
	if(t.size()>0){
		if(t.size()==1)o*=((long double)1/n);else for(i=0;i<t.size()-2;i++)o*=n,o%=k;
	}
	cout<<(long long)o<<"\n";
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

const int MAXN = 111111;

int N, M, MOD;
int f[MAXN], sz[MAXN];

int get(int x) {
	return f[x] == 0 ? x : f[x] = get(f[x]);
}

int main() {

	cin >> N >> M >> MOD;
	for (int i = 1; i <= N; i++) f[i] = 0, sz[i] = 1;
	int cnt = N;
	for (int i = 0; i < M; i++) {
		int u, v; scanf("%d%d", &u, &v);
		u = get(u), v = get(v);
		if (u != v) f[u] = v, cnt--, sz[v] += sz[u], sz[u] = 0;
	}
	if (cnt == 1) {
		if (MOD > 1) puts("1");
		else puts("0");
		return 0;
	}
	int ans = 1;
	for (int i = 1; i <= cnt-2; i++) ans = 1LL*ans*N % MOD;
	for (int i = 1; i <= N; i++) if (sz[i]) ans = 1LL*ans*sz[i] % MOD;
	cout << ans%MOD << endl;
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

const int MAXN = 111111;

int N, M, MOD;
int f[MAXN], sz[MAXN];

int get(int x) {
	return f[x] == 0 ? x : f[x] = get(f[x]);
}

int main() {

	cin >> N >> M >> MOD;
	for (int i = 1; i <= N; i++) f[i] = 0, sz[i] = 1;
	int cnt = N;
	for (int i = 0; i < M; i++) {
		int u, v; scanf("%d%d", &u, &v);
		u = get(u), v = get(v);
		if (u != v) f[u] = v, cnt--, sz[v] += sz[u], sz[u] = 0;
	}
	if (cnt == 1) {
		puts("1");
		return 0;
	}
	int ans = 1;
	for (int i = 1; i <= cnt-2; i++) ans = 1LL*ans*N % MOD;
	for (int i = 1; i <= N; i++) if (sz[i]) ans = 1LL*ans*sz[i] % MOD;
	cout << ans << endl;
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

const int MAXN = 111111;

int N, M, MOD;
int f[MAXN], sz[MAXN];

int get(int x) {
	return f[x] == 0 ? x : f[x] = get(f[x]);
}

int main() {

	cin >> N >> M >> MOD;
	for (int i = 1; i <= N; i++) f[i] = 0, sz[i] = 1;
	int cnt = N;
	for (int i = 0; i < M; i++) {
		int u, v; scanf("%d%d", &u, &v);
		u = get(u), v = get(v);
		if (u != v) f[u] = v, cnt--, sz[v] += sz[u], sz[u] = 0;
	}
	if (cnt == 1) {
		puts("1");
		return 0;
	}
	int ans = 1;
	for (int i = 1; i <= cnt-2; i++) ans = 1LL*ans*N % MOD;
	for (int i = 1; i <= N; i++) if (sz[i]) ans = 1LL*ans*sz[i] % MOD;
	cout << ans%MOD << endl;
	return 0;
}


#include <cstdio>
#include <vector>
using namespace std;

int a;
int b;
int n;
int m;
int idx;
long long int k;
long long int sum;
long long int ans;
int grp[100000];
long long int size[100001];
vector<int> es[100000];

void dfs(int v, int idx) {
    if (grp[v]) return;

    grp[v] = idx;
    size[idx]++;
    for (int i=0; i<es[v].size(); i++) {
        int u = es[v][i];
        dfs(u, idx);
    }
}

int main() {
    scanf("%d %d %lld", &n, &m, &k);
    for (int i=0; i<m; i++) {
        scanf("%d %d", &a, &b);
        --a;
        --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }

    idx = 1;
    for (int i=0; i<n; i++) {
        if (!grp[i]) dfs(i, idx++);
    }

    ans = 1L;
    sum = 0L;
    for (int i=1; i<idx; i++) {
        ans *= size[i];
        ans %= k;
        sum += size[i];
        sum %= k;
    }

    for (int i=1; i<idx-2; i++) {
        ans *= sum;
        ans %= k;
    }

    printf("%lld\n", ans);
}


#include <cstdio>
#include <vector>
using namespace std;

int a;
int b;
int n;
int m;
int idx;
long long int k;
long long int sum;
long long int ans;
int grp[100000];
long long int size[100001];
vector<int> es[100000];

void dfs(int v, int idx) {
    if (grp[v]) return;

    grp[v] = idx;
    size[idx]++;
    for (int i=0; i<es[v].size(); i++) {
        int u = es[v][i];
        dfs(u, idx);
    }
}

int main() {
    scanf("%d %d %lld", &n, &m, &k);
    for (int i=0; i<m; i++) {
        scanf("%d %d", &a, &b);
        --a;
        --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }

    idx = 1;
    for (int i=0; i<n; i++) {
        if (!grp[i]) dfs(i, idx++);
    }

    if (idx == 2) {
        printf("%lld\n", 1%k);
        return 0;
    }

    ans = 1L;
    sum = 0L;
    for (int i=1; i<idx; i++) {
        ans *= size[i];
        ans %= k;
        sum += size[i];
        sum %= k;
    }

    for (int i=1; i<idx-2; i++) {
        ans *= sum;
        ans %= k;
    }

    printf("%lld\n", ans);
}


#include <cstdio>
#include <vector>
using namespace std;

int a;
int b;
int n;
int m;
int idx;
long long int k;
long long int sum;
long long int ans;
int grp[100000];
long long int size[100001];
vector<int> es[100000];

void dfs(int v, int idx) {
    if (grp[v]) return;

    grp[v] = idx;
    size[idx]++;
    for (int i=0; i<es[v].size(); i++) {
        int u = es[v][i];
        dfs(u, idx);
    }
}

int main() {
    scanf("%d %d %lld", &n, &m, &k);
    for (int i=0; i<m; i++) {
        scanf("%d %d", &a, &b);
        --a;
        --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }

    idx = 1;
    for (int i=0; i<n; i++) {
        if (!grp[i]) dfs(i, idx++);
    }

    if (idx == 2) {
        puts("1");
        return 0;
    }

    ans = 1L;
    sum = 0L;
    for (int i=1; i<idx; i++) {
        ans *= size[i];
        ans %= k;
        sum += size[i];
        sum %= k;
    }

    for (int i=1; i<idx-2; i++) {
        ans *= sum;
        ans %= k;
    }

    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 110000

int root[NN], cnt[NN];

VI com;

int find_root(int u){

	return u==root[u] ? u : root[u]=find_root(root[u]);

}

int main() {

	int n, m, k, u, v;

	cin >> n >> m >> k;

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int i=0; i<m; i++){

		scanf("%d %d", &u, &v);

		cnt[find_root(v)]+=cnt[find_root(u)];

		root[find_root(u)]=find_root(v);

	}

	for(int i=1; i<=n; i++) if(i==find_root(i)){

		com.push_back(cnt[i]);

	}

	if(com.size()==1){

		printf("%d\n", 1%k);

		return 0;

	}

	INT ans=1;

	for(int i=com.size(); i--;){

		ans=ans*com[i]%k;

		if(i>1) ans=ans*n%k;

	}

	cout << ans << endl;

	return 0;

}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 100010;

int root[maxn], rank[maxn];

int find_root( int u ) {

	if ( u == root[u] ) return u;

	return root[u] = find_root( root[u] );

}

void accept( int u, int v ) {

	u = find_root( u );

	v = find_root( v );

	if ( u == v ) return;

	root[v] = u;

	rank[u] += rank[v];

}

int main() {

	int n, m, mod, u, v;

	cin >> n >> m >> mod;

	for( int i = 0; i < n; i ++ ) rank[i] = 1, root[i] = i;

	for( int i = 0; i < m; i ++ ) {

		scanf("%d%d", &u, &v);

		u--; v--;

		accept( u, v );

	}

	ll ans = 1;

	int rid = 0;

	for( int i = 0; i < n; i ++ ) {

		if ( root[i] != i ) continue;

		ans = ( ans * rank[i] ) % mod;

		if ( rid > 1 ) ans = ( ans * n ) % mod;

		rid++;

	}

	if ( rid == 1 ) { cout<<1%mod<<endl; return 0; }

	cout << ans << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 110000

int root[NN], cnt[NN];

VI com;

int find_root(int u){

	return u==root[u] ? u : root[u]=find_root(root[u]);

}

int main() {

	int n, m, k, u, v;

	cin >> n >> m >> k;

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int i=0; i<m; i++){

		scanf("%d %d", &u, &v);

		u=find_root(u);

		v=find_root(v);

		if(u==v) continue;

		cnt[v]+=cnt[u];

		root[u]=v;

	}

	for(int i=1; i<=n; i++) if(i==find_root(i)){

		com.push_back(cnt[i]);

	}

	if(com.size()==1){

		printf("%d\n", 1%k);

		return 0;

	}

	INT ans=1;

	for(int i=com.size(); i--;){

		ans=ans*com[i]%k;

		if(i>1) ans=ans*n%k;

	}

	cout << ans << endl;

	return 0;

}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 100010;

int root[maxn], rank[maxn];

int find_root( int u ) {

	if ( u == root[u] ) return u;

	return root[u] = find_root( root[u] );

}

void accept( int u, int v ) {

	u = find_root( u );

	v = find_root( v );

	if ( u == v ) return;

	if ( rank[u] < rank[v] ) swap( u, v );

	root[v] = u;

	rank[u] += rank[v];

}

int main() {

	int n, m, mod, u, v;

	cin >> n >> m >> mod;

	for( int i = 0; i < n; i ++ ) rank[i] = 1, root[i] = i;

	for( int i = 0; i < m; i ++ ) {

		scanf("%d%d", &u, &v);

		u--; v--;

		accept( u, v );

	}

	ll ans = 1;

	int rid = 0;

	for( int i = 0; i < n; i ++ ) {

		if ( find_root( i ) != i ) continue;

		ans = ( ans * rank[i] ) % mod;

		if ( rid > 1 ) ans = ( ans * n ) % mod;

		rid++;

	}

	if ( rid == 1 ) { puts("0"); return 0; }

	cout << ans << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100100

int root[NN], cnt[NN];

int find_root(int u){

	return root[u]==u ? u : root[u]=find_root(root[u]);

}

void join(int u, int v){

	u=find_root(u);

	v=find_root(v);

	if(u==v) return ;

	if(cnt[u]<cnt[v]) swap(u, v);

	cnt[u]+=cnt[v];

	root[v]=u;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, m, k;

	gn(n, m, k);

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int u, v, i=0; i<m; i++){

		gn(u, v);

		join(u, v);

	}

	int ans=1;

	int ct=0;

	for(int i=1; i<=n; i++) if(find_root(i)==i){

		ct++;

		if(ct>2) ans=(INT)ans*n%k;

		ans=(INT)ans*cnt[i]%k;

	}

	println(ans);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

#define NN 110000

int root[NN], cnt[NN];

VI com;

int find_root(int u){

	return u==root[u] ? u : root[u]=find_root(root[u]);

}

int main() {

	int n, m, k, u, v;

	cin >> n >> m >> k;

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int i=0; i<m; i++){

		scanf("%d %d", &u, &v);

		cnt[find_root(v)]+=cnt[find_root(u)];

		root[find_root(u)]=find_root(v);

	}

	for(int i=1; i<=n; i++) if(i==find_root(i)){

		com.push_back(cnt[i]);

	}

	INT ans=1;

	for(int i=com.size(); i--;){

		ans=ans*com[i]%k;

		if(i>1) ans=ans*n%k;

	}

	cout << ans%k << endl;

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100100

int root[NN], cnt[NN];

int find_root(int u){

	return root[u]==u ? u : root[u]=find_root(root[u]);

}

void join(int u, int v){

	u=find_root(u);

	v=find_root(v);

	if(u==v) return ;

	if(cnt[u]<cnt[v]) swap(u, v);

	cnt[u]+=cnt[v];

	root[v]=u;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, m, k;

	gn(n, m, k);

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int u, v, i=0; i<m; i++){

		gn(u, v);

		join(u, v);

	}

	int ans=1;

	int ct=0;

	for(int i=1; i<=n; i++) if(find_root(i)==i){

		ct++;

		if(ct>2) ans=(INT)ans*n%k;

		ans=(INT)ans*cnt[i]%k;

	}

	if(ct==1) ans=1;

	println(ans%k);

	return 0;

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100100

int root[NN], cnt[NN];

int find_root(int u){

	return root[u]==u ? u : root[u]=find_root(root[u]);

}

void join(int u, int v){

	u=find_root(u);

	v=find_root(v);

	if(u==v) return ;

	if(cnt[u]<cnt[v]) swap(u, v);

	cnt[u]+=cnt[v];

	root[v]=u;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int n, m, k;

	gn(n, m, k);

	for(int i=1; i<=n; i++) root[i]=i, cnt[i]=1;

	for(int u, v, i=0; i<m; i++){

		gn(u, v);

		join(u, v);

	}

	int ans=1%k;

	int ct=0;

	for(int i=1; i<=n; i++) if(find_root(i)==i){

		ct++;

		if(ct>2) ans=(INT)ans*n%k;

		ans=(INT)ans*cnt[i]%k;

	}

	println(ans);

	return 0;

}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 100010;

int root[maxn], rank[maxn];

int find_root( int u ) {

	if ( u == root[u] ) return u;

	return root[u] = find_root( root[u] );

}

void accept( int u, int v ) {

	u = find_root( u );

	v = find_root( v );

	if ( u == v ) return;

	if ( rank[u] < rank[v] ) swap( u, v );

	root[v] = u;

	rank[u] += rank[v];

}

int main() {

	int n, m, mod, u, v;

	cin >> n >> m >> mod;

	for( int i = 0; i < n; i ++ ) rank[i] = 1, root[i] = i;

	for( int i = 0; i < m; i ++ ) {

		scanf("%d%d", &u, &v);

		u--; v--;

		accept( u, v );

	}

	ll ans = 1;

	int rid = 0;

	for( int i = 0; i < n; i ++ ) {

		if ( find_root( i ) != i ) continue;

		ans = ( ans * rank[i] ) % mod;

		if ( rid > 1 ) ans = ( ans * n ) % mod;

		rid++;

	}

	cout << ans << endl;

	return 0;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cassert>
#include <ctime>

#define next next_asdf
#define prev prev_asdf
#define y1 y1_asdf
#define ws ws_asdf

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)(a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#ifdef WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;

const ld eps=1e-10;
const int inf=(int)1e9;

/* --- main part --- */

#define TASK_NAME "a"
const int maxn=(int)1e5+10;
const int maxe=(int)2*maxn;
int head[maxn];
int next[maxe];
int to[maxe];
int vc=1;
int mark[maxn];
int C=0;
void add(int x, int y)
{
    vc++;
    to[vc]=y;
    next[vc]=head[x];
    head[x]=vc;
}
void dfs(int x)
{
    mark[x]=1;
    C++;
    for(int e=head[x];e;e=next[e]) if(mark[to[e]]==0) dfs(to[e]);
}
int a[maxn], ac=0;
ll mpow(ll a, ll b, ll mod)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    #ifdef home
    assert(freopen(TASK_NAME".in", "r", stdin));
    assert(freopen(TASK_NAME".out", "w", stdout));
    #endif
    srand(time(NULL));
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x, y;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d", &x, &y);
        x--; y--;
        add(x, y);
        add(y, x);
    }
    for(int i=0;i<n;i++) if(mark[i]==0)
    {
        C=0;
        dfs(i);
        a[ac++]=C;
    }
    ll res=mpow(n, ac-2, k);
    for(int i=0;i<ac;i++) res=(res*a[i])%k;
    cout<< res <<endl;
    #ifdef home
        eprintf("%d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));
    #endif
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cassert>
#include <ctime>

#define next next_asdf
#define prev prev_asdf
#define y1 y1_asdf
#define ws ws_asdf

#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)(a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#ifdef WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;

const ld eps=1e-10;
const int inf=(int)1e9;

/* --- main part --- */

#define TASK_NAME "a"
const int maxn=(int)1e5+10;
const int maxe=(int)2*maxn;
int head[maxn];
int next[maxe];
int to[maxe];
int vc=1;
int mark[maxn];
int C=0;
void add(int x, int y)
{
    vc++;
    to[vc]=y;
    next[vc]=head[x];
    head[x]=vc;
}
void dfs(int x)
{
    mark[x]=1;
    C++;
    for(int e=head[x];e;e=next[e]) if(mark[to[e]]==0) dfs(to[e]);
}
int a[maxn], ac=0;
ll mpow(ll a, ll b, ll mod)
{
    ll res=1;
    while(b)
    {
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
int main()
{
    #ifdef home
    assert(freopen(TASK_NAME".in", "r", stdin));
    assert(freopen(TASK_NAME".out", "w", stdout));
    #endif
    srand(time(NULL));
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int x, y;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d", &x, &y);
        x--; y--;
        add(x, y);
        add(y, x);
    }
    for(int i=0;i<n;i++) if(mark[i]==0)
    {
        C=0;
        dfs(i);
        a[ac++]=C;
    }
    if(ac==1) return 0*printf("%d\n", 1%k);

    ll res=mpow(n, ac-2, k);
    for(int i=0;i<ac;i++) res=(res*a[i])%k;
    cout<< res <<endl;
    #ifdef home
        eprintf("%d ms\n", (int)(clock()*1000.0/CLOCKS_PER_SEC));
    #endif
    return 0;
}


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

int main()
{   int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int arr[100];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        if(n%2==0){
            for(int i=0;i<n;i+=2){
                swap(arr[i],arr[i+1]);
            }

        }
        else{
            int k=floor(n/2);
            swap(arr[k],arr[n-1]);

            for(int i=0;i<k;i++){
                swap(arr[i],arr[i+3]);
            }
            for(int i=0;i<k/2;i++){
                swap(arr[i],arr[i+1]);
            }
        }
        for(int i=0;i<n;i++){
            cout << arr[i]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
using namespace std;

int main()
{   int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int arr[100];
        vector<int> v;
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        if(n%2==0){
            for(int i=0;i<n;i+=2){
                swap(arr[i],arr[i+1]);
            }

        }
        else{
            int k=floor(n/2);
            for(int i=k;i<n;i++){
                v.push_back(arr[i]);
            }
            for(int i=0;i<k;i++){
                v.push_back(arr[i]);
            }
        }
        if(n%2==0){
                for(int i=0;i<n;i++){
                cout << arr[i]<<" ";
            }
            cout<<endl;
        }
        else{
            for(int i=0;i<n;i++){
                cout<<v.at(i)<<" ";
            }
            cout<<endl;
        }

    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[100];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        for(int i=n-1;i>=0;i--){
            cout<<arr[i]<<" ";
        }
        cout<<endl;
    }

}


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

int main()
{   int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int arr[100];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        if(n%2==0){
            for(int i=0;i<n;i+=2){
                swap(arr[i],arr[i+1]);
            }

        }
        else{
            int k=floor(n/2);
            swap(arr[k],arr[n-1]);

            for(int i=0;i<k;i++){
                swap(arr[i],arr[i+3]);
            }
        }
        for(int i=0;i<n;i++){
            cout << arr[i]<<" ";
        }
        cout<<endl;

    }
    return 0;
}


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

int main()
{   int t;
    cin>>t;

    while(t--){
        int n;
        cin>>n;
        int arr[100];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        if(n%2==0){
            for(int i=0;i<n;i+=2){
                swap(arr[i],arr[i+1]);
            }

        }
        else{
            int k=floor(n/2);
            swap(arr[k],arr[n-1]);

            for(int i=0;i<k;i++){
                swap(arr[i],arr[i+3]);
            }
        }
        for(int i=0;i<n;i++){
            cout << arr[i]<<" ";
        }

    }
    return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f;
//const int maxn=;
using namespace std;
typedef long long ll;
int p[105];
int pre[105];
int vis[105];
int ans[105];
//1,2,5,6,3,4
//5,1,6,2,4
int main ()
{
    //freopen("D:\\input.txt", "r", stdin);
    //freopen("D:\\output.txt", "w", stdout);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        pre[0]=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
            pre[i]=p[i]+p[i-1];
        }
        for(int i=1;i<pre[2]-1;i++){
            if(i==p[1])
                continue;
            memset(vis,0,sizeof(vis));
            int cnt=i;
            ans[1]=i;
            int f=1;
            for(int j=2;j<=n;j++){
                cnt=pre[j]-cnt;
                if(vis[pre[cnt]]){
                    f=0;
                    break;
                }
                vis[pre[cnt]]=1;
                ans[j]=cnt;
            }
            if(f){
                for(int k=1;k<=n-1;k++){
                    cout<<ans[k]<<" ";
                }
                cout<<ans[n]<<endl;
                break;
            }
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f;
//const int maxn=;
using namespace std;
typedef long long ll;
int p[105];
int pre[105];
int vis[105];
int ans[105];
//1,2,5,6,3,4
//5,1,6,2,4
int main ()
{
    //freopen("D:\\input.txt", "r", stdin);
    //freopen("D:\\output.txt", "w", stdout);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        pre[0]=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
            pre[i]=p[i]+p[i-1];
        }
        for(int i=1;i<pre[2]-1;i++){
            if(i==p[1])
                continue;
            memset(vis,0,sizeof(vis));
            int cnt=i;
            ans[1]=i;
            int f=1;
            for(int j=2;j<=n;j++){
                cnt=pre[j]-cnt;
                if(vis[pre[cnt]]){
                    f=0;
                    break;
                }
                vis[pre[cnt]]=1;
                ans[j]=cnt;
            }
            if(f){
                for(int k=1;k<=n;k++){
                    cout<<ans[k]<<"";
                }
                break;
            }
        }
    }
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define w(x) int x; cin>>x;while(x--)
using namespace std;
int main() {
	w(x) {
		int n; cin >> n;
		int arr[n];
		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		for (int i = n - 1; i >= 0; i--) cout << arr[i] << " ";
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f;
//const int maxn=;
using namespace std;
typedef long long ll;
int p[105];
int pre[105];
int vis[105];
int ans[105];
//1,2,5,6,3,4
//5,1,6,2,4
int main ()
{
    //freopen("D:\\input.txt", "r", stdin);
    //freopen("D:\\output.txt", "w", stdout);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        pre[0]=0;
        for(int i=1;i<=n;i++){
            cin>>p[i];
            pre[i]=p[i]+p[i-1];
        }
        for(int i=1;i<pre[2]-1;i++){
            if(i==p[1])
                continue;
            memset(vis,0,sizeof(vis));
            int cnt=i;
            ans[1]=i;
            int f=1;
            for(int j=2;j<=n;j++){
                cnt=pre[j]-cnt;
                if(vis[pre[cnt]]){
                    f=0;
                    break;
                }
                vis[pre[cnt]]=1;
                ans[j]=cnt;
            }
            if(f){
                for(int k=1;k<=n-1;k++){
                    cout<<ans[k]<<"";
                }
                cout<<ans[n]<<endl;
                break;
            }
        }
    }
	return 0;
}


#include <bits/stdc++.h>

  // #define int long long
  // #define endl "\n"

  using namespace std;

   void solve()
   {int n;
    cin>>n;
    vector<int> arr(n);
      for(int i=1;i<=n;i++)
        cin>>arr[i];

      if( n%2==0)
      {
        // for(int i=1;i<n;i+=2)
        // {
        //   swap(arr[i],arr[i+1]);
        // }
        for(int i=2;i<=n;i+=2)
        cout<<arr[i]<<" "<<arr[i-1]<<" ";
        cout<<endl;
      }

      else if(n%2!=0)
      {
           int left=1;int c=0;
         int mid=(n+1)/2;
         for(int i=mid;i<=n;i++)
         {
             cout<<arr[i]<<" ";
             c++;
         }
        //  if(c==n)break;
          while(left<mid)
         {
             cout<<arr[left]<<" ";
             left++;c++;
         }
        if(c==n)
        {
        cout<<endl;
        return;
        }

      }

   }
 int main()
  {
    int t;
    cin>>t;
    while(t--)
    {

solve();

    }

 }


#include <bits/stdc++.h>

  // #define int long long
  // #define endl "\n"

  using namespace std;

   void solve()
   {int n;
    cin>>n;
    vector<int> arr(n);
      for(int i=1;i<=n;i++)
        cin>>arr[i];

      if( n%2==0)
      {
        for(int i=1;i<n;i+=2)
        {
          swap(arr[i],arr[i+1]);
        }
        for(int i=1;i<=n;i++)
        cout<<arr[i]<<" ";
        cout<<endl;
      }

      else if(n%2!=0)
      {
           int left=1;int c=0;
         int mid=(n+1)/2;
         for(int i=mid;i<=n;i++)
         {
             cout<<arr[i]<<" ";
             c++;
         }
        //  if(c==n)break;
          while(left<mid)
         {
             cout<<arr[left]<<" ";
             left++;c++;
         }
        if(c==n)
        {
        cout<<endl;
        return;
        }

      }

   }
 int main()
  {
    int t;
    cin>>t;
    while(t--)
    {

solve();

    }

 }


#include <bits/stdc++.h>

  // #define int long long
  // #define endl "\n"

  using namespace std;

 int main()
  {
    int t;
    cin>>t; int n;
    while(t--)
    {

      cin>>n;
    vector<int> arr(n);
      for(int i=1;i<=n;i++)
        cin>>arr[i];

      if( n%2==0)
      {
        for(int i=1;i<n;i+=2)
        {
          swap(arr[i],arr[i+1]);
        }
        for(int i=1;i<=n;i++)
        cout<<arr[i]<<" ";
        cout<<endl;
      }

      else if(n%2!=0)
      {

        reverse(arr.begin(),arr.end());
        for(int i=1;i<=n;i++)
        {
           cout<<arr[i]<<" ";
        }
        cout<<endl;

      }

    }

 }


#include <bits/stdc++.h>

  // #define int long long
  // #define endl "\n"

  using namespace std;

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

    }

  }


#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define vl vector<long long>
#define vi vector<int>
using namespace std;

void solve()
{
	int n;
	cin>>n;
	int ar[n];
	vi v;
	set<int> s;
	int arr[n];

	for(int i=0;i<n;i++) cin>>ar[i];
		sort(ar,ar+n,greater<int>());
	for(int i=0;i<n;i++) cout<<ar[i]<<" ";
		cout<<endl;

}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--)

		solve();
}


#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define vl vector<long long>
#define vi vector<int>
using namespace std;

void solve()
{
	int n;
	cin>>n;
	int ar[n];
	vi v;

	int arr[n];

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

	for(int i=0;i<n-1;i++) v.pb(ar[i]+ar[i+1]);
		sort(v.begin(),v.end());
	sort(arr,arr+n);
	do{
		vi v2;
		int f=1;
		bool flag=0;
		for(int i=0;i<n;i++)
		{
			if(arr[i]!=ar[i]) {f=0;break;}
		}
		if(!f)
		{
			for(int i=0;i<n-1;i++)
			{
				v2.pb(arr[i]+arr[i+1]);
			}
			sort(v2.begin(),v2.end());
			for(int i=0;i<v2.size();i++)
			{
				if(v[i]!=v2[i]){flag=1;break;}
			}
			if(!flag) break;
		}

	}while(next_permutation(arr,arr+n));
	for(int i=0;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;

}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--)

		solve();
}


#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define vl vector<long long>
#define vi vector<int>
using namespace std;

void solve()
{
	int n;
	cin>>n;
	int ar[n];
	vi v;
	int f=1;
	int arr[n];

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

	for(int i=0;i<n-1;i++) v.pb(ar[i]+ar[i+1]);
		sort(v.begin(),v.end());
	sort(arr,arr+n);
	do{
		vi v2;
		bool flag=0;
		for(int i=0;i<n;i++)
		{
			if(arr[i]!=ar[i]) {f=0;break;}
		}
		if(!f)
		{
			for(int i=0;i<n-1;i++)
			{
				v2.pb(arr[i]+arr[i+1]);
			}
			sort(v2.begin(),v2.end());
			for(int i=0;i<v2.size();i++)
			{
				if(v[i]!=v2[i]){flag=1;break;}
			}
			if(!flag) break;
		}

	}while(next_permutation(arr,arr+n));
	for(int i=0;i<n;i++)
	{
		cout<<arr[i]<<" ";
	}
	cout<<endl;

}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--)

		solve();
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector<long long>
#define vi vector<int>
#define endl "\n"
using namespace std;

void solve()
{

	int n;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;i++) cin>>ar[i];
	for(int i=0;i<n;i++) cout<<ar[n-1-i]<<" ";
	cout<<endl;

}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define jaldi_chal ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define rep(i, k) for (ll i = 0; i < k; i++)
#define rew(i, a, b) for (ll i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define M 1000000007
#define dbg(x) cout << #x << " " << x << endl;
#define dbg2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define inf 1e10
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define MAX 10000
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll x, ll y, ll p);
int main()
{
   jaldi_chal
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   ll tc = 1, i, j, k;
   cin >> tc;
   while (tc--)
   {
      ll n;
      cin >> n;
      vi v(n);
      rep(i, n) cin >> v[i];
      rew(i,1,n-1) swap(v[i], v[i -1]);
      tr(v, i) cout << *i << " ";
      cout << "\n";
   }
}
ll power(ll x, ll y, ll p)
{
   int res = 1;
   x = x % p;
   if (x == 0)
      return 0;
   while (y > 0)
   {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define jaldi_chal ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define rep(i, k) for (ll i = 0; i < k; i++)
#define rew(i, a, b) for (ll i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define M 1000000007
#define dbg(x) cout << #x << " " << x << endl;
#define dbg2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define inf 1e10
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define MAX 10000
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll x, ll y, ll p);
int main()
{
   jaldi_chal
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   ll tc = 1, i, j, k;
   cin >> tc;
   while (tc--)
   {
      ll n;
      cin >> n;
      vi v(n);
      rep(i, n) cin >> v[i];
      reverse(all(v));
      tr(v, i) cout
          << *i << " ";
      cout << "\n";
   }
}
ll power(ll x, ll y, ll p)
{
   int res = 1;
   x = x % p;
   if (x == 0)
      return 0;
   while (y > 0)
   {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define jaldi_chal ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define rep(i, k) for (ll i = 0; i < k; i++)
#define rew(i, a, b) for (ll i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define M 1000000007
#define dbg(x) cout << #x << " " << x << endl;
#define dbg2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define inf 1e10
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define MAX 10000
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll x, ll y, ll p);
int main()
{
   jaldi_chal
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   ll tc = 1, i, j, k;
   cin >> tc;
   while (tc--)
   {
      ll n;
      cin >> n;
      vi v(n);
      rep(i, n) cin >> v[i];
      rep(i, n - 1) swap(v[i], v[i + 1]);
      tr(v, i) cout << *i << " ";
      cout << "\n";
   }
}
ll power(ll x, ll y, ll p)
{
   int res = 1;
   x = x % p;
   if (x == 0)
      return 0;
   while (y > 0)
   {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define jaldi_chal ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define rep(i, k) for (ll i = 0; i < k; i++)
#define rew(i, a, b) for (ll i = a; i <= b; i++)
#define ff first
#define ss second
#define pb push_back
#define M 1000000007
#define dbg(x) cout << #x << " " << x << endl;
#define dbg2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define inf 1e10
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define MAX 10000
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll x, ll y, ll p);
int main()
{
   jaldi_chal
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
   ll tc = 1, i, j, k;
   cin >> tc;
   while (tc--)
   {
      ll n;
      cin >> n;
      vi v(n);
      rep(i, n) cin >> v[i];
      swap(v[0], v[1]);
      tr(v, i) cout << *i << " ";
      cout << endl;
   }
}
ll power(ll x, ll y, ll p)
{
   int res = 1;
   x = x % p;
   if (x == 0)
      return 0;
   while (y > 0)
   {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}


                        /************* SRAVAN KUMAR **************/

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fori(a,b) for(long long i=a;i<b;i++)
#define fore(a,b) for(long long i=a;i<=b;i++)
#define fora(m)   for(auto i=m.begin();i!=m.end();i++)
#define sp <<" "<<
#define nl <<"\n"
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define l(s) s.size()

signed main() {
        fast;
       ll t;
       cin>>t;
       while(t--){
            ll n;
            cin>>n;
            ll a[n];
            fori(0,n) cin>>a[i];
            if(n&1)
            swap(a[0],a[n/2]);
            for(ll i=n-1;i>=0;i--)
            cout<<a[i]<<" ";
            cout<<"\n";

       }
	return 0;

}


                        /************* SRAVAN KUMAR **************/

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fori(a,b) for(long long i=a;i<b;i++)
#define fore(a,b) for(long long i=a;i<=b;i++)
#define fora(m)   for(auto i=m.begin();i!=m.end();i++)
#define sp <<" "<<
#define nl <<"\n"
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define l(s) s.size()
signed main() {
        fast;
       ll t;
       cin>>t;
       while(t--){
           ll n;
           cin>>n;
           vector<ll> a(n);
           for(ll &i:a) cin>>i;
           reverse(all(a));
           for(auto x : a) cout<<x<<" ";
           cout<<"\n";
           }
	return 0;

}


                        /************* SRAVAN KUMAR **************/

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fori(a,b) for(long long i=a;i<b;i++)
#define fore(a,b) for(long long i=a;i<=b;i++)
#define fora(m)   for(auto i=m.begin();i!=m.end();i++)
#define sp <<" "<<
#define nl <<"\n"
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define l(s) s.size()
signed main() {
        fast;
       ll t;
       cin>>t;
       while(t--){
           ll n;
           cin>>n;
           vector<ll> a(n);
           for(ll &i:a) cin>>i;
           for(ll i=n-1;i>=0;i--) cout<<a[i]<<" ";
           cout<<"\n";
           }
	return 0;

}


                        /************* SRAVAN KUMAR **************/

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define fori(a,b) for(long long i=a;i<b;i++)
#define fore(a,b) for(long long i=a;i<=b;i++)
#define fora(m)   for(auto i=m.begin();i!=m.end();i++)
#define sp <<" "<<
#define nl <<"\n"
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define l(s) s.size()

signed main() {
        fast;
       ll t;
       cin>>t;
       while(t--){
            ll n;
            cin>>n;
            ll a[n+3];
            fori(0,n) cin>>a[i];
            if(n&1){
            for(ll i=n/2;i<n;i++)
            cout<<a[i]<<" ";
            for(ll i=0;i<n/2;i++)
            cout<<a[i]<<" ";
            }
            else{

            for(ll i=1;i<n;i+=2){
                    swap(a[i],a[i-1]);
            cout<<a[i-1]<<" "<<a[i]<<" ";
            }
            }
            cout<<"\n";

       }
	return 0;

}


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a,b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;
 cin>>x;
 for(i=1;i<n;i++){cin>>y;cout<<y<<" ";}
 cout<<x<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a[900000],b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

 for(i=0;i<n;i++)cin>>a[i];
if(n==2||n==3)
swap(a[0],a[n-1]);
else{
swap(a[0],a[2]);
swap(a[1],a[3]);
}
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a[900000],b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

 for(i=0;i<n;i++)cin>>a[i];
swap(a[0],a[2]);
swap(a[1],a[3])
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a,b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

 for(i=0;i<n;i++)cin>>a[i];
swap(a[0],a[1]);
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a[900000],b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

 for(i=0;i<n;i++)cin>>a[i];
swap(a[0],a[1]);
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a[900000],b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

 for(i=0;i<n;i++)cin>>a[i];
swap(a[0],a[2]);
swap(a[1],a[3]);
for(i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
   }
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a,b,x,y,c,m,d,k;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 whiel(tt--){
 cin>>n;
 cin>>x;
 for(i=1;i<n;i++){cin>>y;cout<<y<<" ";}
 cout<<x<<<endl;
   }


    #include <bits/stdc++.h>
    using namespace std;
    long long n,tt,a[900000],b,x,y,c,m,d,k,i;
    string s;
    map<long long,long long>mp;
    long long power(long long x, unsigned long long y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return power(x, y / 2) * power(x, y / 2);
    else
        return x * power(x, y / 2) * power(x, y / 2);
}
   int main(){
     ios::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
  cin>>tt;
 while(tt--){
 cin>>n;

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

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


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,j,k,l,p,t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n],b[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        for(i=n-1; i>=0; i--)
        {
            cout<<a[i]<<" ";
        }

        cout<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,i,j,k,l,p,t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        if(n%2==0)
        {
            for(i=n-1; i>=0; i--)
            {
                cout<<a[i]<<" ";
            }
        }
        else
        {
            cout<<a[n-1]<<" ";
            for(i=0; i<n-1; i++)
            {
                cout<<a[i]<<" ";
            }
        }
        cout<<endl;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
// #ifndef ONLINE_JUDGE
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
// #endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			int arr[n+10];
			cin>>n;
			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
// #ifndef ONLINE_JUDGE
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
// #endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			int arr[n+10];
			cin>>n;
			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			int arr[n+10];
			cin>>n;
			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			int arr[n+10];
			cin>>n;
			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
// #ifndef ONLINE_JUDGE
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
// #endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			int arr[n+10];
			cin>>n;
			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
}


#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //indexed_set s; x=s.find_by_order(2); at position 2=*x order_of_key(7) find 7 return key, not in set, position it would have in set returned

#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (ll i = a; i <= b; i++)

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    {
// #ifndef ONLINE_JUDGE
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
// #endif
    }
    ll test;
    cin >> test;
    REP(TEST, 1, test)
    {
			int n;
			cin>>n;
			int arr[n+10];

			REP(i,0,n-1){
				cin>>arr[n-1-i];
			}
			REP(i,0,n-1){
				cout<<arr[i]<<" ";
			}
			cout<<"\n";
    }
	return 0;
}


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

void solve()
{
    int n;
    cin >> n;

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

    for(int i=0;i<n;i=i+2)
    {
        int temp = arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
    }

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

cout<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    solve();
}


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

int tc, n, a[111];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> tc;
	while(tc--){
		cin >> n;
		for(int i=1;i<=n;i++) cin >> a[i];
		for(int i=n;i>=1;i--) cout << a[i] << " ";
		cout << "\n";
	}
}


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

void solve()
{
    int n;
    cin >> n;

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

    for(int i=0;i<n;i=i+2)
    {
        int temp = arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
    }

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

cout<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    solve();
}


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

void solve()
{
    int n;
    cin >> n;

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

    for(int i=0;i<n;i=i+2)
    {
        if(i==n-1)
           break;

        int temp = arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
    }

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

cout<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    solve();
}


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

#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).end()
#define pb push_back
#define pf push_front
#define fori(i, a, n) for(int i = a; i < n; ++i)
#define MAX(x) (*max_element(all(x)))
#define MIN(x) (*min_element(all(x)))
#define sortarr(a, n) sort(a, a + n)
#define sortvec(V) sort(all(V))

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

typedef unordered_map<int, int, custom_hash> u_map;
typedef unordered_set<int, int, custom_hash> u_set;
typedef vector<int> V;
typedef pair<int , int> pairi;
typedef set<int> seti;
typedef priority_queue<int> p_queue;
typedef deque<int> deqi;

const int MOD = 1e9+7;
const int INF = 1e9+8;
const double pi = 3.14159265359;

void solve()
{
    int n;
    cin >> n;

    int arr[n];
    fori(i,0,n)
        cin>>arr[i];

    for(int i=0;i<n;i=i+2)
    {
        int temp  =arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
    }

    fori(i,0,n)
        cout<<arr[i]<<" ";
    cout<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    solve();
}


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

void solve()
{
    int n;
    cin >> n;

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

    for(int i=0;i<n;i=i+2)
    {
        if(i==n-1)
           break;

        int temp = arr[i];
        arr[i] = arr[i+1];
        arr[i+1] = temp;
    }

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

cout<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while(t--)
    solve();
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n,m=0,s=0;
        cin>>n;
        int a[n],b[n],c[n-1],d[n-1];
        for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];}
        for(int i=0;i<n-1;i++)
        c[i]=a[i]+a[i+1];
        sort(c,c+(n-1));
        while (next_permutation(a, a + n)){
            m=0,s=0;
            for(int i=0;i<n;i++){
                if(b[i]==a[i]){
                m++;
                break;}
            }
            if(m!=0)
            continue;
            else{
                for(int i=0;i<n-1;i++)
                d[i]=a[i]+a[i+1];
                sort(d,d+(n-1));
                for(int i=0;i<n-1;i++){
                    if(d[i]!=c[i])
                    s++;
                }
                if(s==0){
                    for(int i=0;i<n;i++)
                    cout<<a[i]<<" ";
                }
            }
        }
        cout<<endl;
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n,;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
        cin>>a[i];
        for(int i=n-1;i>=0;i--)
        cout<<a[i];
        }
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n;
        cin>>n;
        int a[n]
        for(int i=0;i<n;i++){
        cin>>a[i];
        for(int i=n-1;i>=0;i++)
        cout<<a[i];
        }
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n,;
        cin>>n;
        int a[n]
        for(int i=0;i<n;i++){
        cin>>a[i];
        for(int i=n-1;i>=0;i++)
        cout<<a[i];
        }
    }
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int t;
    cin>>t;
    for(int i=0;i<t;i++){
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        for(int i=n-1;i>=0;i--)
        cout<<a[i]<<" ";
        cout<<endl;
        }
    }


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n];
		for(int i=0;i<n;i++){
			cin>>p[i];
		}
		int m=n-1;
		int f[m];
		for(int i=0;i<m;i++){
			f[i]=p[i]+p[i+1];
		}
		sort(f,f+m);
		if(n%2==0){
			for(int i=n-1;i>=0;i--){
				cout<<p[i]<<" ";
			}}
			else{
				for(int i=0;i<n;i++){
					cout<<p[(i+1)%n]<<" ";
				}

		}
		cout<<"\n";
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n];
		for(int i=0;i<n;i++){
			cin>>p[i];
		}
		int m=n-1;
		int f[m];
		for(int i=0;i<m;i++){
			f[i]=p[i]+p[i+1];
		}
		sort(f,f+m);
		int k=0;
		for(int i=n-1;i>=0;i--){
			cout<<p[i]<<" ";
		}
		cout<<"\n";
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n];
		for(int i=0;i<n;i++){
			cin>>p[i];
		}
		int m=n-1;
		int f[m];
		for(int i=0;i<m;i++){
			f[i]=p[i]+p[i+1];
		}
		sort(f,f+m);
		if(n<=2){
			for(int i=n-1;i>=0;i--){
				cout<<p[i]<<" ";
			}}
			else{
				for(int i=0;i<n;i++){
					cout<<p[(i+2)%n]<<" ";
				}

		}
		cout<<"\n";
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n];
		for(int i=0;i<n;i++){
			cin>>p[i];
		}
		int m=n-1;
		int f[m];
		for(int i=0;i<m;i++){
			f[i]=p[i]+p[i+1];
		}
		sort(f,f+m);
		int k=0;
		while(k<n){
			if(n%2==0){
				cout<<p[k+1]<<" "<<p[k]<<" ";
				k+=2;
			}
			else{
				for(int i=0;i<n;i++){
					cout<<p[(i+2)%n]<<" ";
				}
				break;

			}
		}
		cout<<"\n";
	}

}


#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n];
		for(int i=0;i<n;i++){
			cin>>p[i];
		}
		int m=n-1;
		int f[m];
		for(int i=0;i<m;i++){
			f[i]=p[i]+p[i+1];
		}
		sort(f,f+m);
		for(int i=0;i<n;i++){
			cout<<p[(i+1)%n]<<" ";
				}
		cout<<"\n";
	}

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define fi first
#define se second
#define db double
#define U unsigned
#define P pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fo(i,a,b) for(int i = a;i < b;++i)
#define ro(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
 cin>>t;
 while(t--)
 {
    vector<int> v1,v2;
    int n;
    cin>>n;
    int a[n];
    fo(i,0,n)
     cin>>a[i];

    if(n%2==0)
    {
     for(int i=0;i<n;i+=2)
     {
       if((i+1)%2==1)
       {  int temp;
           temp=a[i];
           a[i]=a[i+1];
           a[i+1]=temp;}
      }
      for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
      cout<<endl;
     }
     else
       {
        for(int i=0;i<n;i++)
        {
         if(a[i]%2==0)
           v1.pb(a[i]);
         else
           v2.pb(a[i]);
         }
        for(int i=0;i<v2.size();i++)
          cout<<v2[i]<<" ";
       for(int i=0;i<v1.size();i++)
          cout<<v1[i]<<" ";
        cout<<endl;
        }    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define fi first
#define se second
#define db double
#define U unsigned
#define P pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fo(i,a,b) for(int i = a;i < b;++i)
#define ro(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
 cin>>t;
 while(t--)
 {
    int n;
    cin>>n;
    int a[n];
    fo(i,0,n)
     cin>>a[i];
    sort(a,a+n,greater<>());
    fo(i,0,n)
     cout<<a[i]<<" ";
    cout<<endl;}
    /*if(n%2==0)
    {
     for(int i=0;i<n;i+=2)
     {
       if((i+1)%2==1)
       {  int temp;
           temp=a[i];
           a[i]=a[i+1];
           a[i+1]=temp;}
      }
     }
     else
       {
      */
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define fi first
#define se second
#define db double
#define U unsigned
#define P pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fo(i,a,b) for(int i = a;i < b;++i)
#define ro(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
 cin>>t;
 while(t--)
 {
    vector<int> v1,v2;
    int n;
    cin>>n;
    int a[n];
    fo(i,0,n)
     cin>>a[i];
    for(int i=n-1;i>=0;i--)
       cout<<a[i]<<" ";
    cout<<endl;
   }
return 0;
}
  /*  if(n%2==0)
    {
     for(int i=0;i<n;i+=2)
     {
       if((i+1)%2==1)
       {  int temp;
           temp=a[i];
           a[i]=a[i+1];
           a[i+1]=temp;}
      }
      for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
      cout<<endl;
     }
     else
       {
        for(int i=0;i<n;i++)
        {
         if(a[i]%2==0)
           v1.pb(a[i]);
         else
           v2.pb(a[i]);
         }
        for(int i=0;i<v2.size();i++)
          cout<<v2[i]<<" ";
       for(int i=0;i<v1.size();i++)
          cout<<v1[i]<<" ";
        cout<<endl;
        }    }
    return 0;
}*/


#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define fi first
#define se second
#define db double
#define U unsigned
#define P pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fo(i,a,b) for(int i = a;i < b;++i)
#define ro(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
 cin>>t;
 while(t--)
 {
    vector<int> v1,v2;
    int n;
    cin>>n;
    int a[n];
    fo(i,0,n)
     cin>>a[i];

    if(n%2==0)
    {
     for(int i=0;i<n;i++)
        {
         if(a[i]%2==0)
           v1.pb(a[i]);
         else
           v2.pb(a[i]);
         }

      for(int i=0;i<n;i++)
       {
         if(i%2==0)
           cout<<v2[i/2]<<" ";
         else
             cout<<v1[i/2]<<" ";

     } cout<<endl;}
     else
       {
        for(int i=0;i<n;i++)
        {
         if(a[i]%2==0)
           v1.pb(a[i]);
         else
           v2.pb(a[i]);
         }
        for(int i=0;i<v2.size();i++)
          cout<<v2[i]<<" ";
       for(int i=0;i<v1.size();i++)
          cout<<v1[i]<<" ";
        cout<<endl;
        }
      for(int i=0;i<v1.size();i++)
         v1.pop_back();
      for(int i=0;i<v2.size();i++)
         v2.pop_back();
        }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define fi first
#define se second
#define db double
#define U unsigned
#define P pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fo(i,a,b) for(int i = a;i < b;++i)
#define ro(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
 cin>>t;
 while(t--)
 {
    int n;
    cin>>n;
    int a[n];
    fo(i,0,n)
     cin>>a[i];
    sort(a,a+n);
    fo(i,0,n)
     cout<<a[i]<<" ";
    cout<<endl;}
    /*if(n%2==0)
    {
     for(int i=0;i<n;i+=2)
     {
       if((i+1)%2==1)
       {  int temp;
           temp=a[i];
           a[i]=a[i+1];
           a[i+1]=temp;}
      }
     }
     else
       {
      */
    return 0;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int t;
    cin >> t;
        while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << " \n"[i == 1];
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << "\n"[i == 1];
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    int a[n];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << " \n"[i == 1];
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << " \n"[i == 1];
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    int a[n + 1];
    while (t--) {
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << " \n"[i == 1];
    }
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int n;
    cin >> n;
    int a[n];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << "\n"[i == 1];
    return false;
}


/// Quality Over Quantity

#include <bits/stdc++.h>

#define FILE_NAME "A"

using namespace std;
using ll = long long;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define SZ(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define what_is(x) cerr << #x << " is " << x << endl;

void freekick() {
#ifndef ONLINE_JUDGE
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
}

const int dx[] = {-1, +1, 0, 0, -2, +2, -1, +1};
const int dy[] = {0, 0, -1, +1, +1, +1, +2, +2};

const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void freegoal() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

signed main() {
    freekick();
    freegoal();
    int t;
    cin >> t;
        while (t--) {
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = n; i >= 1; i--)
        cout << a[i] << " \n"[i == 1];
      }
    return false;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
       long long int n,i,sum=0;
       cin>>n;
       long long int a[n];
       for(i=0;i<n;i++)
       cin>>a[i];
       if(n%2==0)
       {

           for(i=0;i<n-1;i+=2)
           swap(a[i],a[i+1]);
       }
       else
       {
           sum=n/2;
           for(i=sum-1;i>=0;i--)
           swap(a[i],a[n-i-1]);

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

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
       long long int n,i;
       cin>>n;
       long long int a[n],sum=0,ans=1000000001;
       for(i=0;i<n;i++)
       cin>>a[i];
       for(i=0;i<n;i++)
       {
           sum+=a[i];
           ans=min(ans,sum);
        }
        cout<<abs(ans)<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
       long long int n,i;
       cin>>n;
       long long int a[n];
       for(i=0;i<n;i++)
       cin>>a[i];
       if(n%2==0)
       {

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

           for(i=0;i<n/2;i++)
           swap(a[i],a[n-i-1]);

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

    }
    return 0;
}


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


#include <bits/stdc++.h>
using namespace std;
vector<int> sum(vector<int>& t)
{
    vector<int> s;
    for (int i = 0; i < t.size()-1; ++i)
    {
        s.push_back(t[i] + t[i+1]);
    }
    sort(s.begin(), s.end());
    return s;
}
int compare(vector<int>& t1, vector<int>& t2)
{
    for (int i=0; i<t1.size(); ++i)
    if (t1[i] != t2[i])return 0;
    return 1;
}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n,x;
        cin >> n;
        vector<int> res, initial, resSum, iniSum;
        for (int i =0; i < n; i++)
        {
            cin >> x;
            res.push_back(x);
            initial.push_back(i+1);
        }
        resSum = sum(res);
        do {
            iniSum = sum(initial);
            if (compare(iniSum, resSum))
                break;
        }while (next_permutation(initial.begin(), initial.begin() + n));
        for (int i = 0; i < n; i++)
            cout << initial[i] <<" ";
            cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> sum(vector<int>& t, vector<int>&sum)
{
    vector<int> s;
    for (int i = 0; i < t.size()-1; ++i)
    {
        if(sum.size() > 0 && find(sum.begin(), sum.end(), t[i] + t[i+1]) == sum.end())
            {
                return s;
            }
        s.push_back(t[i] + t[i+1]);
    }
    sort(s.begin(), s.end());
    return s;
}
int compare(vector<int>& t1, vector<int>& t2)
{
    for (int i=0; i<t1.size(); ++i)
    if (t1[i] != t2[i])return 0;
    return 1;
}
int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        int n,x;
        scanf("%d", &n);
        vector<int> res, initial, resSum, iniSum;
        for (int i =0; i < n; i++)
        {
            scanf("%d", &x);
            res.push_back(x);
            initial.push_back(i+1);
        }
        resSum = sum(res, iniSum);
        do {
            iniSum = sum(initial, resSum);
            if (iniSum.size() != resSum.size())
                continue;
            if (compare(iniSum, resSum) && !compare(initial, res))
                break;
        }while (next_permutation(initial.begin(), initial.begin() + n));
        for (int i = 0; i < n; i++)
            printf("%d ", initial[i]);
        printf("\n");
    }
    return 0;
}