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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
const double pi = acos(-1.0);
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int minimum(int b, int e, int a[ ]){
    int i, mn=INT_MAX;
    for(i=b;i<=e;i++)mn=min(mn, a[i]);
    return mn;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int t;
    cin>>t;
    while(t--){
        int n, i, idx, j, c=0;
        cin>>n; int a[n+1];
        map <int, int> mp; set<int> s;
        for(i=1;i<=n;i++){
            cin>>a[i];mp[a[i]]=i;
        }
        idx=1;
        for(i=1;i<=n;i++){
                int mn=minimum(idx, n, a);
                j=mp[mn];
                s.insert(a[i]);
                while(j>idx){
                    swap(a[j], a[j-1]);
                    j--;
                    c++;
                    if(c==n-1)break;
                }
                if(s.sz==i && *s.begin()==1)idx=mp[mn]+1;
                else idx=mp[mn];
            if(c==n-1)break;
        }
        for(i=1;i<=n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
const double pi = acos(-1.0);
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define MOD 1000000007
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

int minimum(int b, int e, int a[ ]){
    int i, mn=101;
    for(i=b;i<=e;i++)if(a[i]<mn)mn=a[i];
    return mn;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen ("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    #endif
    int t;
    cin>>t;
    while(t--){
        int n, i, idx, j, c=0;
        cin>>n; int a[n+1];
        map <int, int> mp; set<int> s;
        for(i=1;i<=n;i++){
            cin>>a[i];mp[a[i]]=i;
        }
        idx=1;
        for(i=1;i<=n;i++){
                int mn=minimum(idx, n, a);
                j=mp[mn];
                s.insert(a[i]);
                while(j>idx){
                    swap(a[j], a[j-1]);
                    j--;
                    c++;
                    if(c==n-1)break;
                }
                if(s.sz==i && *s.begin()==1 && i==n)break;
                else if(s.sz==i && *s.begin()==1)idx=mp[mn]+1;
                else idx=mp[mn];
            if(c==n-1)break;
        }
        for(i=1;i<=n;i++)cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}


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

const int maxn=1500;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        memset(b,0,sizeof(b));
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0)
                {
                    if(a[j-1]>a[j]){
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                    }
                    else{
                        break;
                    }
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}
//111
//6
//5 2 6 4 3 1
//1 5 2 6 4 3
//6
//2 6 5 4 3 1
//1 2 6 5 4 3
//6
//6 4 2 5 3 1
//1 6 4 2 5 3
//6
//5 6 2 1 4 3
//1 5 6 2 3 4
//


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

const int maxn=1500;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        memset(b,0,sizeof(b));
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0)
                {
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

const int maxn=150;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0&&b[ mapp[i] ]==0)
                {
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


#include<string>
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4;
int a[maxn];
int judge[105][105];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        memset(judge,0,sizeof(judge));
        int m;
        cin>>m;
        for(int i=0;i<m;++i)
        {
            scanf("%d",&a[i]);
        }
        for(int k=0;k<m;++k)
        for(int i=m-1;i>=1;--i)
        {
            if(a[i]<a[i-1]&&judge[i][i-1]==0)
            {
                swap(a[i],a[i-1]);
                judge[i][i-1]=1;
            }
        }
        for(int i=0;i<m;++i)
        {
            printf("%d",a[i]);
            if(i==m-1) printf("\n");
            else printf(" ");
        }
    }
    return 0;
}


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

const int maxn=150;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        memset(b,0,sizeof(b));
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0&&b[ mapp[i] ]==0)
                {
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

const int maxn=150;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0)
                {
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

const int maxn=150;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0)
                {
                    --number;
                    swap(a[j],a[j-1]);
                    mapp[ a[j] ]=j-1;
                    mapp[a[j-1]]=j;
                    b[j-1]=1;
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}


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

const int maxn=1500;

int a[maxn],b[maxn];
map<int,int>mapp;

void init()
{
    memset(b,0,sizeof(b));
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        mapp.clear();
        memset(b,0,sizeof(b));
        init();
        int n;
        cin>>n;
        for(int i=1; i<=n; ++i)
        {
            scanf("%d",&a[i]);
            mapp[ a[i] ]=i;
        }
        int number=n-1;
        for(int i=1; i<=n; ++i)
        {
            for(int j=mapp[i]; j>i; --j )
            {
                if(number==0) break;
                if(b[j-1]==0)
                {
                    if(a[j-1]>a[j]){
                    --number;
                    swap(a[j],a[j-1]);
                    b[j-1]=1;
                    }
                }
                else{
                    break;
                }
            }
        }
        for(int i=1; i<=n; ++i)
        {
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
    return 0;
}
//111
//6
//5 2 6 4 3 1
//1 5 2 6 4 3
//6
//2 6 5 4 3 1
//1 2 6 5 4 3
//6
//6 4 2 5 3 1
//1 6 4 2 5 3
//6
//5 6 2 1 4 3
//1 5 6 2 3 4
//


#include <bits/stdc++.h>
using namespace std ;
#define ll long long
int d()
{
    int t ;
    scanf( "%d", &t ) ;
    return t ;
}
ll lld()
{
    ll t ;
    scanf( "%lld", &t ) ;
    return t ;
}
const long long N = 2e5+20,OO=0x3f3f3f3f,mod=1e9+7;
int arr[200];

int main()
{
    int t=d();
    while(t--){
        int n=d();
        int op=0;
        for(int i=0;i<n;i++)scanf("%d",arr+i);
        int st=1;

        for(int i=0;i<n;i++){
            if(arr[i]==st){
                st++;
            }
            else{
                int temp=0;
                int j;
                for( j=i+1;j<n;j++)
                    if(arr[j]==st)break;
                    else temp++;
                if(op+temp+1 <=n-1){
                    for(int y=j;y>i;y--)arr[y]=arr[y-1];

                    arr[i]=st;
                    op+=temp+1;
                    st++;
                }

            }
        }
         for(int i=0;i<n;i++)printf("%d ",arr[i]);
         puts("");
    }
}


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

const int N=1e7+30;
typedef long long ll;
int t,n;
int arr[200];

void solve()
{
    int op=n-1;
    for(int i=1; i<=n && op; i++)
    {
    }

    for(int i=1;i<n;i++)cout<<arr[i]<<" ";
    cout<<arr[n]<<endl;
}

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

}


#include <bits/stdc++.h>
using namespace std ;
#define ll long long
int d()
{
    int t ;
    scanf( "%d", &t ) ;
    return t ;
}
ll lld()
{
    ll t ;
    scanf( "%lld", &t ) ;
    return t ;
}
const long long N = 2e5+20,OO=0x3f3f3f3f,mod=1e9+7;
int arr[200];

int main()
{
    int t=d();
    while(t--){
        int n=d();
        int op=0;
        for(int i=0;i<n;i++)scanf("%d",arr+i);
        int st=1;

        for(int i=0;i<n;i++){
            if(arr[i]==st){
                st++;
            }
            else{
                int temp=0;
                int j;
                for( j=i+1;j<n;j++)
                    if(arr[j]==st)break;
                    else temp++;
                if(op+temp+1 <=n-1){
                    for(int y=j;y>i;y--)if(y-1>i)arr[y]=arr[y-1];
                    arr[i+1]=arr[i];
                    arr[i]=st;
                    op+=temp+1;
                    st++;
                }

            }
        }
        //cout<<op<<"\n";
         for(int i=0;i<n;i++)printf("%d ",arr[i]);
         puts("");
    }
}


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

const int N=1e7+30;
typedef long long ll;
int t,n;
int arr[200];

void solve()
{
    int op=n-1;
    int pos=1;
    int idx;
    while(op &&pos<=n)
    {

        int mn=INT_MAX;
        for(int i=pos; i<=n; i++)
        {
            if(arr[i]<mn)
            {
                mn=arr[i];
                idx=i;
            }
        }
        if(idx==pos){pos++;continue;}
        for(int i=idx; i>pos && op; i--)
        {
            swap(arr[i],arr[i-1]);
            op--;
        }
        pos=idx;
    }
}

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

        for(int i=1; i<=n; i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

}


//        Mostafa Mounir Shehab

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

#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>

void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}

inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}

const int N=1e2 + 5,MOD=1e9 + 7;
int arr[N];

ll n,m,k,cnt,dot,idx,len;
ll a,b,c,mid,l,r;

void valid(){

	len=n-1;

	for(int i=0;i<n && len;++i){
		int idx=i;
		for(int j=i;j<n;++j)
			if(arr[j] < arr[idx])
				idx=j;
		if(idx == i)
			continue;
		for(int j=idx;j>i;--j)
			swap(arr[j],arr[j-1]),--len;
		i=idx-1;
	}

}

int main(){
	int T=D();
	while(T--){

		scanf("%d",&n);
		for(int i=0;i<n;++i)
			scanf("%d",arr+i);

		valid();
		for(int i=0;i<n;++i)
			printf("%d ",arr[i]);
		puts("");

	}

}


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

const int N=1e7+30;
typedef long long ll;
int t,n;
int arr[200];

void solve()
{
    int op=n-1;
    for(int i=1; i<=n && op; i++)
    {
    }

    for(int i=1;i<n;i++)cout<<arr[i]<<" ";
    cout<<arr[n]<<endl;
}

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

}


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

const int N=1e7+30;
typedef long long ll;
int t,n;
int arr[200];

void solve()
{
    int op=n-1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(arr[j]==i){
                for(int x=j;x>i;x--){
                    swap(arr[x],arr[x-1]);
                    op--;
                    if(op==0)break;
                }

                break;
            }

        }
        if(op==0)break;

    }

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

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

}


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

const int N=1e7+30;
typedef long long ll;
int t,n;
int arr[200];

void solve()
{
    int op=n-1;
    int last=1;
    for(int i=1; i<=n && op; i++)
    {
        int idx=-1;
        for(int j=last; j<=n; j++)
            if(arr[j]==i)
            {
                idx=j;
                break;
            }
        for(int j=idx;j>last&&op;j--){
            swap(arr[j],arr[j-1]);op--;
        }

        last++;
    }
}

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

        for(int i=1; i<=n; i++)
            cout<<arr[i]<<" ";
        cout<<endl;
    }

}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	for(int i=1;i<n;i++){
		for(int j=vis[i];j>i-1&&x;j--){
			//vis[a[j]] = j-1;
			//vis[a[j-1]] = j;
			swap(a[j],a[j-1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int v = 0;
	for(int i=1;i<n;i++){
		for(int j=vis[i]-1;j>=max(v,i-1)&&x;j--){
			//vis[a[j]] = j-1;
			//vis[a[j-1]] = j;
			swap(a[j],a[j+1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}
		if(v == vis[i])v = v++;
		else v = vis[i];
		//cout<<v<<endl;
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int pos = 0;
	for(int i=1;i<n;i++){
		int parbo = max(pos,i-1);
		for(int j = vis[i];j>parbo&&x;j--){
			//cout<<j<<endl;
			swap(a[j],a[j-1]);
			x--;
		}
		if(pos == vis[i]){
			pos++;
		}else{
			pos = vis[i];
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int v = 0;
	for(int i=1;i<n;i++){
		for(int j=vis[i]-1;j>=max(v,i-1)&&x;j--){
			//vis[a[j]] = j-1;
			//vis[a[j-1]] = j;
			swap(a[j],a[j+1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}v = vis[i]-1;
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int pos = 0;
	for(int i=1;i<n;i++){
		int parbo = max(pos,i-1);
		if(parbo==n) break;
		for(int j = vis[i];j>parbo&&x;j--){
			//cout<<j<<endl;
			if(a[j]<a[j-1])
			swap(a[j],a[j-1]);
			x--;
		}
		if(pos == vis[i]){
			pos++;
		}else{
			pos = vis[i];
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int x = n-1;
	int pos = 0;
	int idx = 0;
	while(pos<n&&x){
		int mn = INT_MAX;
		for(int i=pos;i<n;i++){
			if(a[i]<mn){
				mn = a[i];
				pos = i;
			}
		}//cout<<pos<<endl;
		for(int i=pos; i>idx&&x;i--){
			swap(a[i],a[i-1]);
			x--;
		}
		if(pos == idx) pos++;
		idx = pos;
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	for(int i=1;i<=n;i++){
		for(int j=vis[i];j>i-1&&x;j--){
			swap(a[j],a[j-1]);
			x--;
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


/*
Author: Fuadul Hasan(fuadul202@gmail.com)
BSMRSTU,Gopalganj
*/
#include<bits/stdc++.h>
using namespace std;
void    		print(int n)    {printf("%d ", n);}
void    		printl(long long n)     {printf("%I64d ", n);}
long long    	readline(){long long x;scanf("%I64d", &x);return x;}
/*
1.#define  gcd(a,b) __gcd(a,b) 2. #define  lcm(a,b) (a*b)/gcd(a,b) 3. #define  PI acos(-1.0) 4.#define  sqr(x) ((x)*(x))
5.#define  min3(a,b,c) min(a,min(b,c))6.#define  min4(a,b,c,d) min(d,min(a,min(b,c)))7.#define  max3(a,b,c) max(a,max(b,c))
8.#define  max4(a,b,c,d) max(d,max(a,max(b,c)))
*/
//.............ignore it................//
/*....... scanf.......*/
template <typename T> inline void readline(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
/*..........error........*/
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {
  vector<string>v; stringstream ss(s); string x;
  while (getline(ss, x, c))v.emplace_back(x); return move(v);
} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
typedef   pair<int, int> ii;
typedef   std::vector<ii> vii;
#define   vi   std::vector<int>
#define   vll  std::vector<ll>
#define   all(n) n.begin(),n.end()
#define  mpsi std::map<string, int>
#define  pb             push_back
#define  ll             long long int
#define  nl             printf("\n");
#define  happy          cin.tie(0);
#define  coding         ios::sync_with_stdio(false);
int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int mod           = 1e9 + 7;
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int N1            = 1e5 + 5;
bool vis[N1];
int a[N1];
vector<int>v[N1];

int solve()
{
	//happy coding
	int n;
	readline(n);
	int a[n+1];
	for(int i=0;i<n;i++){
		readline(a[i]);
	}
	bool boro = false;
	memset(vis,false,sizeof(vis));
	for(int i=0;i<n;i++){
		if(i==0){
			a[i] = 1;
			vis[i+1] = true;
		}else if(a[i]!=n){
			int x = a[i];
			if(a[i]==i+1&&!boro){
				a[i] = i+1;
				vis[i+1] = true;
				continue;
			}
			while(x++&&x<=n){
				if(!vis[x]){
					a[i] = x;
					vis[x] = true;
					boro = true;
					break;
				}
			}
		}else if(a[i]==n){
			if(i==n-1){
				a[i] = n;
			}else{
				if(a[i]==i+1&&!boro){
				a[i] = i+1;
				vis[i+1] = true;
				continue;
				}
				int x = a[i];
				while(x--&&x>=1){
					if(!vis[x]){
						a[i] = x;
						vis[x] = true;
						break;
					}
				}
			}
		}
	}

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

	//error();
}

int main(){
	int test = 1, tc = 0;
	scanf("%d", &test);//(void)getchar();
	while (test--){
		solve();
	}
	return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	for(int i=1;i<n;i++){
		for(int j=vis[i];j>i-1&&x;j--){
			vis[a[j]] = j-1;
			vis[a[j-1]] = j;
			swap(a[j],a[j-1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	for(int i=1;i<=n;i++){
		for(int j=vis[i];j>i-1&&x;j--){
			vis[a[j]] = j-1;
			vis[a[j-1]] = j;
			swap(a[j],a[j-1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int v = 0;
	for(int i=1;i<n;i++){
		for(int j=vis[i]-1;j>=max(v,i-1)&&x;j--){
			//vis[a[j]] = j-1;
			//vis[a[j-1]] = j;
			swap(a[j],a[j+1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}
		if(v == vis[i])v = v++;
		else v = vis[i];
		if(v==n) break;
		//cout<<v<<endl;
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int x = n-1;
	int pos = 0;
	int idx = 0;
	while(pos<n-1&&x){
		int mn = INT_MAX;
		for(int i=pos;i<n;i++){
			if(a[i]<mn){
				mn = a[i];
				pos = i;
			}
		}
		if(pos == idx){
			idx++;
			pos++;
		}
		for(int i=pos; i>idx&&x;i--){
			swap(a[i],a[i-1]);
			x--;
		}
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		vis[a[i]] = i;
	}
	int x = n-1;
	int v = 0;
	for(int i=1;i<n;i++){
		for(int j=vis[i]-1;j>=max(v,i-1)&&x;j--){
			//vis[a[j]] = j-1;
			//vis[a[j-1]] = j;
			swap(a[j],a[j+1]);
			x--;
			/*for(int k=0;k<n;k++){
				cout<<a[k]<<" ";
			}cout<<endl;*/
		}v = vis[i];
		//cout<<v<<endl;
	}

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

	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr>
#define pr pair<int, int>
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
ll vis[N],res[N];

int solve()
{
	//happy coding

	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	int pos = 0;
	while(pos<n){
		int next = min_element(a.begin()+pos,a.end()) - a.begin();
		int x = a[next];
		a.erase(a.begin()+next);
		a.insert(a.begin()+pos,x);
		if(pos == next) pos++;
		else pos = next;
	}
	vout(a);
	return 0;
}
int main(){
	int test = 1;
	scanf("%d", &test);
	while (test--)solve();return 0;
}


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

using ll = long long;

int main(){
    int times;
    cin >> times;
    while( times-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        bool operation[n+1];
        memset( operation, false, sizeof operation );
        int now = 1;
        int t = n-1;
        while( now < n ){
            int tempOp = -1;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == now && now != i ){
                    tempOp = i-1;
                    break;
                }
            }
            bool flag = true;
            if( tempOp != -1 && tempOp > 0 && v[tempOp] > now ){
                ///cout << tempOp << endl;
                if( operation[tempOp] == false  ){
                    ///t--;
                    flag = false;
                    operation[tempOp] = true;
                    swap( v[tempOp], v[tempOp+1] );
                }
            }
            if( v[now] == now || flag ){
                now++;
            }
        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int pos = 1;
        int target = 1;
        int ace = n-1;
        map<pair<int,int>, bool>mp;
        bool bal = true;
        for( int i = 1; i <= n; i++ ){
            if( v[i] != i ){
                bal = false;
            }
        }
        if( bal == true ){
            for( int i = 1; i <= n; i++ ){
                cout << v[i] << " ";
            }
            cout << endl;
            continue;
        }
        while( true ){
            int st = 0;
            for( int i = pos; i <= n; i++ ){
                if( v[i] == target && i != target ){
                    st = i;
                }else if( v[i] == i ){
                pos++;}
            }

            for( int i = st; i > pos; i-- ){
                if( ace ==0 ){
                    break;
                }
                swap(v[i], v[i-1]);
                ace--;
            }
            pos = st;
            target++;
            if( pos == n ){
                break;
            }
        }

        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int pos = 1;
        int target = 1;
        int ace = n-1;
        map<pair<int,int>, bool>mp;
        bool bal = true;
        for( int i = 1; i <= n; i++ ){
            if( v[i] != i ){
                bal = false;
            }
        }
        if( bal == true ){
            for( int i = 1; i <= n; i++ ){
                cout << v[i] << " ";
            }
            cout << endl;
            continue;
        }
        int last = n;
        int fr = 1;
        while(true){
            int s = fr;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == target && i != target ){
                    s = i;
                }else if( v[i] == i && fr == i ){
                    fr++;
                }
            }

            for( int i = s; i > fr; i-- ){
                if( ace == 0 ){
                    break;
                }
                swap( v[i], v[i-1] );
                ace--;
            }
            if( s != 0 ){
                fr = s;
            }
            if( fr == n || ace == 0 ){
                break;
            }
            target++;
        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

using ll = long long;

int main(){
    int times;
    cin >> times;
    while( times-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        bool operation[n+1];
        memset( operation, false, sizeof operation );
        int now = 1;
        int t = n-1;
        while( t-- ){
            int tempOp = -1;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == now && operation[i-1] == false && now != i ){
                    tempOp = i-1;
                    break;
                }
            }
            if( tempOp != -1 ){
                ///cout << tempOp << endl;
                operation[tempOp] = true;
                swap( v[tempOp], v[tempOp+1] );
            }
            if( v[now] == now ){
                now++;
            }
        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int cnt = 1;
        int pos = 1;
        while( cnt < n ){
            bool f = true;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == pos && i != pos  ){
                    cnt++;
                    swap( v[i-1], v[i] );
                    f = false;
                    break;
                }
            }
            if( v[pos] == pos ){
                pos++;
            }else if( f ){
                break;
            }

        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int pos = 1;
        int target = 1;
        int ace = n-1;
        map<pair<int,int>, bool>mp;
        while( true ){
            int st = 0;

            for( int i = pos; i <= n; i++ ){
                if( v[i] == target && i != target ){
                    st = i;
                }
            }
            if( st == 0 ){
                break;
            }
            for( int i = st; i > pos; i-- ){
                if( ace ==0 ){
                    break;
                }
                swap(v[i], v[i-1]);
                ace--;
            }
            pos = st;
            target++;
            if( pos == n ){
                break;
            }
        }

        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int cnt = 1;
        int pos = 1;
        while( cnt < n ){
            bool f = true;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == pos && i != pos  ){
                    cnt++;
                    swap( v[i-1], v[i] );
                    f = false;
                    break;
                }
            }
            if( v[pos] == pos ){
                pos++;
            }
            if( f ){
                break;
            }
        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


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

int main()
{
    int q;
    cin >> q;
    while( q-- ){
        int n;
        cin >> n;
        vector<int>v(n+2);
        for( int i = 1; i <= n; i++ ){
            cin >> v[i];
        }
        int pos = 1;
        int target = 1;
        int ace = n-1;
        map<pair<int,int>, bool>mp;
        bool bal = true;
        for( int i = 1; i <= n; i++ ){
            if( v[i] != i ){
                bal = false;
            }
        }
        if( bal == true ){
            for( int i = 1; i <= n; i++ ){
                cout << v[i] << " ";
            }
            cout << endl;
            continue;
        }
        int last = n;
        int fr = 1;
        while(true){
            int s = fr;
            for( int i = 1; i <= n; i++ ){
                if( v[i] == target && i != target ){
                    s = i;
                }else if( v[i] == i && fr == i ){
                    fr++;
                }
            }

            for( int i = s; i > fr; i-- ){
                if( ace == 0 ){
                    break;
                }
                swap( v[i], v[i-1] );
                ace--;
            }
            if( s != 0 ){
                fr = s;
            }
            if( fr == n ){
                break;
            }
            target++;
        }
        for( int i = 1; i <= n; i++ ){
            cout << v[i] << " ";
        }
        cout << endl;
    }
}


/** BiSmIlLaHiR rAhMaNiR rAhIm **\
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
            \**  DIIT(17th batch) **/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define endl "\n"
#define pb push_back
#define makep make_pair
#define MOD 1000000007
#define PI acos(-1.0)
#define white 1
#define gray 2
#define black 3
#define PII pair<ll, ll>
#define SIZE 1000005
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
ll fx[]={1,0,-1,0,-1,-1,1,1};
ll fy[]={0,1,0,-1,-1,1,-1,1};

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio();
    ll n,t,i;
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll a[n],count=n-1,j=0,pos,pos1;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        pos=0;
        while(pos<n-1)
        {
            ll mini=1e9,minipos;
            for(i=pos;i<n;i++)
            {
                if(a[i]<mini)
                {
                    mini=a[i];
                    minipos=i;
                }
            }
            //cout<<mini<<" "<<a[minipos]<<endl;
            if(a[pos]==mini)
            {
                pos++;
                continue;
            }
            for(i=minipos;i>pos;i--)
            {
                swap(a[i],a[i-1]);
            }
            pos=minipos;
            //cout<<pos<<endl;
            /*if(j==2)
            break;
            j++;*/
        }
        for(i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[b[m]-1]){
                m++;
                continue;
            }else if(a[b[m]]>a[b[m]-1]){
                m++;
                continue;
            }
            else{
                l[b[m]-1]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        while(m<n){
            if(k>n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else{
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n),c(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        rep(i,n) c[i]=b[i];
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[b[m]]){
                m++;
                continue;
            }
            else{
                l[b[m]]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n),c(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        rep(i,n) c[i]=b[i];
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[b[m]-1]){
                m++;
                continue;
            }else if(a[b[m]]>a[b[m]-1]){
                m++;
                continue;
            }
            else{
                l[b[m]-1]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[b[m]]){
                m++;
                continue;
            }
            else{
                l[b[m]]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=1,m=0;
        cin>>n;
        lvec a(n),b(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        while(m<n){
            if(k>n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else{
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n),c(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        rep(i,n) c[i]=b[i];
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[b[m]-1]){
                m++;
                continue;
            }
            else{
                l[b[m]-1]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<string> svec;

int main(){
    ll q;
    cin>>q;
    rep(j,q){
        ll n,k=0,m=0;
        cin>>n;
        lvec a(n),b(n),c(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            b[a[i]]=i;
        }
        rep(i,n) c[i]=b[i];
        vector<bool> l(n,false);
        while(m<n){
            if(k>=n-1) break;
            if(a[m]==m){
                m++;
                continue;
            }else if(l[c[m]]){
                m++;
                continue;
            }
            else{
                l[c[m]]=true;
                swap(a[b[m]],a[b[m]-1]);
                ll p=b[m];
                b[m]=b[m]-1;
                b[a[p]]=p;
                k++;
                continue;
            }
        }
        rep(i,n){
            a[i]++;
            cout<<a[i]<<" ";
        }
        cout<<endl;
    }
}


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

void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve22(){
    int n, pos, next, swaps;
       		cin>>n;
		vector<int> arr(n+1);
		swaps = 0;
		for (int i=1; i<=n; i++)
		cin>>arr[i];
		next = 1;
		while (next <= n && swaps < (n-1))
		{
			if (arr[next] == next)
			next += 1;
			else
			{
				for (int i=1; i<=n; i++)
				{
					if (arr[i] == next)
					pos = i;
				}
				swap(arr[pos], arr[pos-1]);
				swaps += 1;
			}
		}
		for (int i=1; i<=n; i++)
		{
			cout<<arr[i]<<" ";
		}
		cout<<endl;
}
void solve(){
    int a,b,n,s;
		cin>>a>>b>>n>>s;
		int k=0;
		int c=0,x=-1,f=0;
		do
		{
			c=s-k;
			if(c>=0 && c%n==0)
			{
				x=c/n;
			}
			if(x!=-1 && x<=a)
			{
				f=1;
			}
			k++;
		}while(k<=b && f!=1);
		print(f);
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve22();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void swap(ll a, ll b)
{
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void fff(){
        ll n;
       cin>>n;
       ll a[n],i,b[n]={0},temp,j=1,k,x=1;
       for(i=0;i<n;i++)
       cin>>a[i];
       while(x!=0)
       {
           for(i=0;i<n;i++)
           {
               if(a[i]==j)
               {
                   for(k=i;k>=0;k--)
                   {
                       if(k-1!=-1 && b[k]!=0)
                       {
                           swap(a[k],a[k-1]);
                           cout<<a[k]<<" "<<a[k-1]<<endl;
                           b[k]=1;
                       }
                   }
                   break;
               }
           }

           j++;
           if(j==n)
           x=0;
       }
       for(i=0;i<n;i++)
       {
           cout<<a[i]<<" ";
       }

}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve223(){
    int n,a[101],i,min1,start;
    		cin >>n;
		for (i=1;i<=n;++i) cin>>a[i];
		int k=n;
		if (n==1) {
			for (i=1;i<=n;++i) cout<<a[i]<<" ";
			cout <<"\n";
		}
		else{
			start=1;
			while (start<=n&&k-1>0){
				min1 =a[start];
				for (i=start;i<=n;++i) min1=min(min1,a[i]);
				int j=start;
				while (a[j]!=min1) j++;
				if (k-1-(j-start)>=0){
					for (i=j;i>=start+1;--i) swap(a[i],a[i-1]);
					k-=j-start;
				}else {
					for (i=1;i<=k-1;++i){
						swap(a[j],a[j-1]);
						j--;
					}
				}

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

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
int flag[105];
int arr[105];
#include <set>
#include <queue>
#include <limits>
#include <iomanip>
using namespace std;
struct node {
    long long int a;
    long long int b;
};

void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void swap(ll a, ll b)
{
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void Dijkstra (long long int src, queue <pair<double,long long int>> Q[], long long int V, double D[]){
    D [src] = 0.0;
    set <long long int>  visited;
    priority_queue<pair<double,long long int>, vector<pair<double,long long int>>, greater<pair<double,long long int>>> pq;
    pq.push(make_pair(0.0, src));
    while (visited.size()  <  V){
        long long int u;
        long long int v;
        long long int j;
        u = pq.top().second;
        pq.pop();
        visited.insert(u);

        while(!Q[u].empty()){
        	v = Q[u].front().second;
        	if (D[v] >  D[u] + Q[u].front().first){
        		D[v] =  D[u] + Q[u].front().first;
        		pq.push(make_pair(D[v], v));
        	}
        	Q[u].pop();
        }
    }
}
void fff(){
        		int n;
		cin>>n;
		vector<int>v;
		map<int,int> m;
		for(int i=0;i<n;i++)
		{
			int t;
			cin>>t;
			v.push_back(t);
			m[t]=i;
		}
		int rem=n-1;
		for(int i=1;i<=n;i++)
		{
			if(rem==0) break;
			if(m[i]==(i-1)) continue;
			if(m[i]-(i-1)<=rem)
			{
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second<m[i] && it->first>i)
					it->second++;
				}
				rem=rem-(m[i]-(i-1));
				m[i]=i-1;
			}
			else
			{
				int t=m[i]-rem;
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second>=t && it->second<m[i])
					it->second++;
				}
				m[i]=t;
				rem=0;
			}

		}
        for(auto it=m.begin();it!=m.end();it++)
			{
				v[it->second]=it->first;
			}
			for(int i=0;i<n;i++)
			cout<<v[i]<<" ";
			cout<<endl;

}
void nikki(){
    long long int i, j;
        long long int k, N;
        long long int M, K;
        long long int x, y;
        cin >> x;
        cin >> y;
        cin >> N;
        cin >> M;
        cin >> K;
        long long int c, V;
        V = N + M + K + 1 ;
        struct node Arr[V];
        queue <pair<double,long long int>> Q[V];
        queue <pair<double,long long int>> R[V];
        double distn;
        c = 0;
        Arr[c].a = x;
        Arr[c].b = y;
        c+= 1;
        for(i = 0;i<N;i++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
            distn = (double)sqrt(pow(Arr[c].a-Arr[0].a , 2)  +  pow(Arr[c].b-Arr[0].b , 2));
            Q[0].push(make_pair(distn,c));
            c+= 1;
        }
        for(j = 0;j<M;j++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
        for(i = 0;i<N;i++){
            distn = (double)sqrt(pow(Arr[c].a-Arr[i+1].a, 2) + pow(Arr[c].b-Arr[i+1].b, 2));
            Q[i+1].push(make_pair(distn,c));
        }
            c+= 1;
        }
        for(k = 0;k<K;k++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
        for(j = 0;j<M;j++){
            distn = (double)sqrt(pow(Arr[c].a-Arr[j+N+1].a,2)+pow(Arr[c].b-Arr[j+N+1].b,2));
            Q[j+N+1].push(make_pair(distn,c));
        }
        	c+= 1;
        }
    	double D1[V] ;
    	for(i = 0;i<V;i++){
    		D1[i] = std::numeric_limits<double>::infinity();
    	}
        Dijkstra(0,Q,V,D1);
        c=N+1;
        for(j = 0;j<M;j++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[0].a , 2)  +  pow(Arr[c].b-Arr[0].b , 2));
        	R[0].push(make_pair(distn,c));
        	c+= 1;
        }
        c = 1;
        for(i = 0;i<N;i++){
        for(j = 0;j<M;j++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[j+N+1].a,2)+pow(Arr[c].b-Arr[j+N+1].b,2));
        	R[j+N+1].push(make_pair(distn,c));
        }
        	c+= 1;
        }
        c = N+M+1;
        for(k = 0;k<K;k++){
        for(i = 0;i<N;i++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[i+1].a, 2) + pow(Arr[c].b-Arr[i+1].b, 2));
        	R[i+1].push(make_pair(distn , c));
        }
        	c+= 1;
        }
        double D2[V];
        for(i = 0;i<V;i++){
        	D2[i] = std::numeric_limits<double>::infinity();
        }
        Dijkstra(0, R, V, D2);
        double min1, min2;
    	min1 = D1 [N+M+1];
    	for(i=N+M+1;i<V;i++){
    		if (D1[i]< min1){
    			min1=D1[i];
    		}
    	}

    	min2 = D2 [N+M+1];
    	for(i=N+M+1;i<V;i++){
    		if (D2[i]< min2){
    			min2=D2[i];
    		}
    	}

    	if (min1 < min2){
    		cout << fixed << setprecision(10) << min1 << "\n";
    	}
    	else{
    		cout << fixed << setprecision(10) << min2 << "\n";
    	}
}
void fhh(){
    long long int a,b,m,n,i,j,t,pos,k;
        long long int mn=1000000000;
        cin>>n;

        for(i=1;i<=n;i++)
        {
            cin>>arr[i];
        }
        for(i=1;i<n;i++) flag[i]=0;
            for(j=2;j<=n;j++){
                mn=1234500000;
                for( k=1;k<=n;k++){
                    if(arr[k]==k) continue;
                    if(arr[k]<=mn){
                        mn=arr[k];
                        pos=k;

                    }

                }
                if(flag[pos]==0 ){
                        flag[pos]=1;
                        swap(arr[pos],arr[pos-1]);
                    }
            }
        for(i=1;i<=n;i++) cout<<arr[i]<<" ";
        cout<<endl;
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve223(){
           	    ll n, moves;
        cin>>n>>moves;
        string s;
        cin>>s;

        vector<ll>zeroloc;
        for(int i=0; i<n; i++){
            if(s[i]=='0')
                zeroloc.push_back(i);
        }
        int bestst=0;
        for(int i=0; i<zeroloc.size() && moves>0; i++){
            int cpos = zeroloc[i];
            while(s[bestst]=='0')   bestst++;

            if(bestst>cpos)
                continue;
            else if(cpos-bestst <= moves){
                swap(s[bestst], s[cpos]);
                moves = moves - (cpos-bestst);
            }
            else{
                swap(s[cpos], s[cpos-moves]);
                moves =0;
            }
        }
        cout<<s<<endl;
}
int findminIndex(int *a,int n,int b)
{
	for(int i=0;i<n;i++) {
		if(a[i]==b) return i;
	}
	return 0;
}

int main () {
    int t;

    cin>>t;
    while(t--)
    {
        fhh();
    }
    return 0;
}


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

void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve22(){
        long long int n;
         cin>>n;
		int a[10000],flag[10000]={0},i,j,temp;
		map<int, int> mp;
		for(i=1;i<=n;i++)
		{cin>>a[i];mp[a[i]]=i;}
		for(i=1;i<=n;i++)
		{
			if(i==a[i])
			continue;
			else
			{
				for(j=mp[a[i]];j>i;j--)
				{
					if(flag[j]!=1)
					{flag[j-1]=1;

						temp=a[j];
						a[j]=a[j-1];
						a[j-1]=temp;
						mp[a[j]]=j;mp[a[j-1]]=j-1;
					}

				}
			}
		}
		for(i=1;i<=n;i++)
		cout<<a[i]<<" ";
		cout<<"\n";
}
void solve(){
    int a,b,n,s;
		cin>>a>>b>>n>>s;
		int k=0;
		int c=0,x=-1,f=0;
		do
		{
			c=s-k;
			if(c>=0 && c%n==0)
			{
				x=c/n;
			}
			if(x!=-1 && x<=a)
			{
				f=1;
			}
			k++;
		}while(k<=b && f!=1);
		print(f);
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve22();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void fff(){
     int a,b,n,m,res,ara[sz],s[sz];
        cin>>n;
        memset(s,0,sizeof(s));
        memset(ara,0,sizeof(ara));
        for(int i=0; i<n; i++)
        {
            cin>>ara[i];
            s[i]=ara[i];
        }
        sort(s,s+n);
        int cnt=1;
        int mn;
        int j=0;
           for(int i=j+1; i<n&&j<n; i++)
            {
                if(ara[i]==s[j])
                {
                    while(ara[i]<ara[i-1]&&i>j)
                    {
                        swap(ara[i],ara[i-1]);
                        i--;
                        cnt++;
                        if(cnt==n)
                            break;
                    }
                    i=j;
                    j++;
                }
                if(cnt==n)
                    break;
            }

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

            cout<<ara[i]<<" ";
        }
        cout<<endl;

}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve22(){
    int n, pos, next, swaps;
       		cin>>n;
		vector<int> arr(n+1);
		swaps = 0;
		for (int i=1; i<=n; i++)
		cin>>arr[i];
		next = 1;
		while (next <= n && swaps < (n-1))
		{
			if (arr[next] == next)
			next += 1;
			else
			{
				for (int i=1; i<=n; i++)
				{
					if (arr[i] == next)
					pos = i;
				}
				swap(arr[pos], arr[pos-1]);
				swaps += 1;
			}
		}
		for (int i=1; i<=n; i++)
		{
			cout<<arr[i]<<" ";
		}
		cout<<endl;
}
void solve(){
    int a,b,n,s;
		cin>>a>>b>>n>>s;
		int k=0;
		int c=0,x=-1,f=0;
		do
		{
			c=s-k;
			if(c>=0 && c%n==0)
			{
				x=c/n;
			}
			if(x!=-1 && x<=a)
			{
				f=1;
			}
			k++;
		}while(k<=b && f!=1);
		print(f);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       fff();

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
int flag[105];
int arr[105];
#include <set>
#include <queue>
#include <limits>
#include <iomanip>
using namespace std;
struct node {
    long long int a;
    long long int b;
};

void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void swap(ll a, ll b)
{
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void Dijkstra (long long int src, queue <pair<double,long long int>> Q[], long long int V, double D[]){
    D [src] = 0.0;
    set <long long int>  visited;
    priority_queue<pair<double,long long int>, vector<pair<double,long long int>>, greater<pair<double,long long int>>> pq;
    pq.push(make_pair(0.0, src));
    while (visited.size()  <  V){
        long long int u;
        long long int v;
        long long int j;
        u = pq.top().second;
        pq.pop();
        visited.insert(u);

        while(!Q[u].empty()){
        	v = Q[u].front().second;
        	if (D[v] >  D[u] + Q[u].front().first){
        		D[v] =  D[u] + Q[u].front().first;
        		pq.push(make_pair(D[v], v));
        	}
        	Q[u].pop();
        }
    }
}
void fff(){
        		int n;
		cin>>n;
		vector<int>v;
		map<int,int> m;
		for(int i=0;i<n;i++)
		{
			int t;
			cin>>t;
			v.push_back(t);
			m[t]=i;
		}
		int rem=n-1;
		for(int i=1;i<=n;i++)
		{
			if(rem==0) break;
			if(m[i]==(i-1)) continue;
			if(m[i]-(i-1)<=rem)
			{
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second<m[i] && it->first>i)
					it->second++;
				}
				rem=rem-(m[i]-(i-1));
				m[i]=i-1;
			}
			else
			{
				int t=m[i]-rem;
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second>=t && it->second<m[i])
					it->second++;
				}
				m[i]=t;
				rem=0;
			}

		}
        for(auto it=m.begin();it!=m.end();it++)
			{
				v[it->second]=it->first;
			}
			for(int i=0;i<n;i++)
			cout<<v[i]<<" ";
			cout<<endl;

}
void nikki(){
    long long int i, j;
        long long int k, N;
        long long int M, K;
        long long int x, y;
        cin >> x;
        cin >> y;
        cin >> N;
        cin >> M;
        cin >> K;
        long long int c, V;
        V = N + M + K + 1 ;
        struct node Arr[V];
        queue <pair<double,long long int>> Q[V];
        queue <pair<double,long long int>> R[V];
        double distn;
        c = 0;
        Arr[c].a = x;
        Arr[c].b = y;
        c+= 1;
        for(i = 0;i<N;i++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
            distn = (double)sqrt(pow(Arr[c].a-Arr[0].a , 2)  +  pow(Arr[c].b-Arr[0].b , 2));
            Q[0].push(make_pair(distn,c));
            c+= 1;
        }
        for(j = 0;j<M;j++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
        for(i = 0;i<N;i++){
            distn = (double)sqrt(pow(Arr[c].a-Arr[i+1].a, 2) + pow(Arr[c].b-Arr[i+1].b, 2));
            Q[i+1].push(make_pair(distn,c));
        }
            c+= 1;
        }
        for(k = 0;k<K;k++){
            cin>>Arr[c].a;
            cin>>Arr[c].b;
        for(j = 0;j<M;j++){
            distn = (double)sqrt(pow(Arr[c].a-Arr[j+N+1].a,2)+pow(Arr[c].b-Arr[j+N+1].b,2));
            Q[j+N+1].push(make_pair(distn,c));
        }
        	c+= 1;
        }
    	double D1[V] ;
    	for(i = 0;i<V;i++){
    		D1[i] = std::numeric_limits<double>::infinity();
    	}
        Dijkstra(0,Q,V,D1);
        c=N+1;
        for(j = 0;j<M;j++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[0].a , 2)  +  pow(Arr[c].b-Arr[0].b , 2));
        	R[0].push(make_pair(distn,c));
        	c+= 1;
        }
        c = 1;
        for(i = 0;i<N;i++){
        for(j = 0;j<M;j++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[j+N+1].a,2)+pow(Arr[c].b-Arr[j+N+1].b,2));
        	R[j+N+1].push(make_pair(distn,c));
        }
        	c+= 1;
        }
        c = N+M+1;
        for(k = 0;k<K;k++){
        for(i = 0;i<N;i++){
        	distn = (double)sqrt(pow(Arr[c].a-Arr[i+1].a, 2) + pow(Arr[c].b-Arr[i+1].b, 2));
        	R[i+1].push(make_pair(distn , c));
        }
        	c+= 1;
        }
        double D2[V];
        for(i = 0;i<V;i++){
        	D2[i] = std::numeric_limits<double>::infinity();
        }
        Dijkstra(0, R, V, D2);
        double min1, min2;
    	min1 = D1 [N+M+1];
    	for(i=N+M+1;i<V;i++){
    		if (D1[i]< min1){
    			min1=D1[i];
    		}
    	}

    	min2 = D2 [N+M+1];
    	for(i=N+M+1;i<V;i++){
    		if (D2[i]< min2){
    			min2=D2[i];
    		}
    	}

    	if (min1 < min2){
    		cout << fixed << setprecision(10) << min1 << "\n";
    	}
    	else{
    		cout << fixed << setprecision(10) << min2 << "\n";
    	}
}
void fhh(){
    long long int a,b,m,n,i,j,t,pos,k;
        long long int mn=1000000000;
        cin>>n;

        for(i=1;i<=n;i++)
        {
            cin>>arr[i];
        }
        for(i=1;i<n;i++) flag[i]=0;
            for(j=2;j<=n;j++){
                mn=1234500000;
                for( k=1;k<=n;k++){
                    if(arr[k]==k) continue;
                    if(arr[k]<=mn){
                        mn=arr[k];
                        pos=k;

                    }

                }
                if(flag[pos]==0 ){
                        flag[pos]=1;
                        swap(arr[pos],arr[pos-1]);
                    }
            }
        for(i=1;i<=n;i++) cout<<arr[i]<<" ";
        cout<<endl;
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve223(){
           	    ll n, moves;
        cin>>n>>moves;
        string s;
        cin>>s;

        vector<ll>zeroloc;
        for(int i=0; i<n; i++){
            if(s[i]=='0')
                zeroloc.push_back(i);
        }
        int bestst=0;
        for(int i=0; i<zeroloc.size() && moves>0; i++){
            int cpos = zeroloc[i];
            while(s[bestst]=='0')   bestst++;

            if(bestst>cpos)
                continue;
            else if(cpos-bestst <= moves){
                swap(s[bestst], s[cpos]);
                moves = moves - (cpos-bestst);
            }
            else{
                swap(s[cpos], s[cpos-moves]);
                moves =0;
            }
        }
        cout<<s<<endl;
}
int findminIndex(int *a,int n,int b)
{
	for(int i=0;i<n;i++) {
		if(a[i]==b) return i;
	}
	return 0;
}

 const int N = 2e5+9, M = 1e7, OO = 0x7f7f7f7f;
map<int , int>m;

signed main() {
	int q, n, pos, next, swaps;
	cin>>q;
	while (q--)
	{
		cin>>n;
		vector<int> arr(n+1);
		vector<bool> visited(n+1);
		swaps = 0;
		for (int i=1; i<=n; i++)
		cin>>arr[i];
		next = 1;
		while (next <= n && swaps < (n-1))
		{
			if (arr[next] == next)
			next += 1;
			else
			{
				for (int i=1; i<=n; i++)
				{
					if (arr[i] == next)
					pos = i;
				}
				if (visited[pos] == 0 && arr[pos-1] > arr[pos])
				{
					swap(arr[pos], arr[pos-1]);
					swaps += 1;
					visited[pos] = 1;
				}
				else
				next += 1;
			}
		}
		for (int i=1; i<=n; i++)
		{
			cout<<arr[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
int flag[105];
int arr[105];
void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void swap(ll a, ll b)
{
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void fff(){
        		int n;
		cin>>n;
		vector<int>v;
		map<int,int> m;
		for(int i=0;i<n;i++)
		{
			int t;
			cin>>t;
			v.push_back(t);
			m[t]=i;
		}
		int rem=n-1;
		for(int i=1;i<=n;i++)
		{
			if(rem==0) break;
			if(m[i]==(i-1)) continue;
			if(m[i]-(i-1)<=rem)
			{
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second<m[i] && it->first>i)
					it->second++;
				}
				rem=rem-(m[i]-(i-1));
				m[i]=i-1;
			}
			else
			{
				int t=m[i]-rem;
				for(auto it=m.begin();it!=m.end();it++)
				{
					if(it->second>=t && it->second<m[i])
					it->second++;
				}
				m[i]=t;
				rem=0;
			}

		}
        for(auto it=m.begin();it!=m.end();it++)
			{
				v[it->second]=it->first;
			}
			for(int i=0;i<n;i++)
			cout<<v[i]<<" ";
			cout<<endl;

}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve223(){
           	    ll n, moves;
        cin>>n>>moves;
        string s;
        cin>>s;

        vector<ll>zeroloc;
        for(int i=0; i<n; i++){
            if(s[i]=='0')
                zeroloc.push_back(i);
        }
        int bestst=0;
        for(int i=0; i<zeroloc.size() && moves>0; i++){
            int cpos = zeroloc[i];
            while(s[bestst]=='0')   bestst++;

            if(bestst>cpos)
                continue;
            else if(cpos-bestst <= moves){
                swap(s[bestst], s[cpos]);
                moves = moves - (cpos-bestst);
            }
            else{
                swap(s[cpos], s[cpos-moves]);
                moves =0;
            }
        }
        cout<<s<<endl;
}
int main()
{
        int a,b,m,n,i,j,t,mn,pos,k;
    cin>>t;
    while(t--)
    {
        fff();
    }
    return 0;
}


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

void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve22(){
            int n;
       		cin >> n;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		bool block[n][n];
		memset(block, 0, sizeof block);
		for (int i = 1; i <= n; ++i) {
			int pos;
			for (int j = 0; j < n; ++j) {
				if (a[j] == i) pos = j;
			}
			for (int k = pos; k > 0; --k) {
				if (not block[k][k-1]) {
					swap(a[k], a[k-1]);
					block[k][k-1] = 1;
				}
			}
		}
		for (int i = 0; i < n; ++i) cout << a[i] << " ";
		cout << endl;
}
void solve(){
    int a,b,n,s;
		cin>>a>>b>>n>>s;
		int k=0;
		int c=0,x=-1,f=0;
		do
		{
			c=s-k;
			if(c>=0 && c%n==0)
			{
				x=c/n;
			}
			if(x!=-1 && x<=a)
			{
				f=1;
			}
			k++;
		}while(k<=b && f!=1);
		print(f);
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve22();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void fff(){
     int a,b,n,m,res,ara[sz],s[sz];
        cin>>n;
        memset(s,0,sizeof(s));
        memset(ara,0,sizeof(ara));
        for(int i=0; i<n; i++)
        {
            cin>>ara[i];
            s[i]=ara[i];
        }
        sort(s,s+n);
        int cnt=1;
        int mn;
        for(int j=0; j<n; j++)
        {
            mn=s[j];

            for(int i=j+1; i<n; i++)
            {
                if(ara[i]==mn)
                {
                    while(ara[i]<ara[i-1])
                    {
                        swap(ara[i],ara[i-1]);
                        i--;
                        cnt++;
                        if(cnt==n)
                            break;
                    }

                    i=j;
                }
                if(cnt==n)
                    break;
            }
            if(cnt==n)
                break;
        }

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

            cout<<ara[i]<<" ";
        }
        cout<<endl;
}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve22(){
    int n, pos, next, swaps;
       		cin>>n;
		vector<int> arr(n+1);
		swaps = 0;
		for (int i=1; i<=n; i++)
		cin>>arr[i];
		next = 1;
		while (next <= n && swaps < (n-1))
		{
			if (arr[next] == next)
			next += 1;
			else
			{
				for (int i=1; i<=n; i++)
				{
					if (arr[i] == next)
					pos = i;
				}
				swap(arr[pos], arr[pos-1]);
				swaps += 1;
			}
		}
		for (int i=1; i<=n; i++)
		{
			cout<<arr[i]<<" ";
		}
		cout<<endl;
}
void solve(){
    int a,b,n,s;
		cin>>a>>b>>n>>s;
		int k=0;
		int c=0,x=-1,f=0;
		do
		{
			c=s-k;
			if(c>=0 && c%n==0)
			{
				x=c/n;
			}
			if(x!=-1 && x<=a)
			{
				f=1;
			}
			k++;
		}while(k<=b && f!=1);
		print(f);
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       fff();

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 20002
void print(int f){
        if(f==0)
		{
			cout<<"NO"<<endl;
		}
		else
		{
			cout<<"YES"<<endl;
		}
}
void swap(ll a, ll b)
{
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void fff(){
        ll n;
       cin>>n;
       ll a[n],i,b[n]={0},temp,j=1,k,x=1;
       for(i=0;i<n;i++)
       cin>>a[i];
       while(x!=0)
       {
           for(i=0;i<n;i++)
           {
               if(a[i]==j)
               {
                   for(k=i;k>=0;k--)
                   {
                       if(k-1!=-1 && b[k]!=0)
                       {
                           swap(a[k],a[k-1]);
                           cout<<a[k]<<" "<<a[k-1]<<endl;
                           b[k]=1;
                       }
                   }
                   break;
               }
           }

           j++;
           if(j==n)
           x=0;
       }
       for(i=0;i<n;i++)
       {
           cout<<a[i]<<" ";
       }

}
void solve33(){
    int a,b,n,s,x,y,f;
        f=0;
    	cin>>a>>b>>n>>s;
    	int h=min(s/n,a),l=0;
    	while(l<=h){
    		int m=(l+h)/2;
    		x=m;
    		y=s-n*x;
    		if(y>=0 and y<=b){
    			cout<<"YES\n";
    			f=1;break;
    		}
    		else if(y>b){
    			l=m+1;
    		}
    		else if(y<0){
    			h=m-1;
    		}
    	}
    	if(f==0) cout<<"NO\n";
}

void solve223(){
            int n;
        cin>>n;
        vector <int > a;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
        	a.push_back(x);
        }
        bool sw[n-1];
        for(int i=0;i<n-1;i++)
            sw[n-1]=false;
        int turn=n-1;
        for(int i=1;i<=n;++i){
            auto it=find(a.begin(),a.end(),i);
            int k=distance(a.begin(),it);
            if(turn==0)
                break;
            if(k==i-1)
                continue;
            else{
                for(int j=k;j>i-1;--j){
                    if(turn==0)
                        break;
                    else if(!sw[j-1]&&a[j-1]>a[j]){
                        swap(a[j],a[j-1]);
                        sw[j-1]=true;
                        --turn;
                    }
                    else
                        break;
                }
            }

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

    }
    return 0;
}


#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
int main(){
    std::ios::sync_with_stdio(false);
    ll n, k;
    while( cin >> n >> k ) {
        string s;
        cin >> s;
        bool flag = false;
        for( ll i = 0; i < s.length(); i ++ ) {
            if( i + k < s.length() ) {
                if( s[i] != s[i+k] ) {
                    flag = true;
                    break;
                }
            }
        }
        if( flag ) {
            for( ll i = 0; i < s.length(); i ++ ) {
                if( s[i] == '.' ) {
                    cout << "0";
                } else {
                    cout << s[i];
                }
            }
        } else {
            cout << "No";
        }
        cout << endl;
    }
    return 0;
}


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

bool checkPeriod(string s, int p) {
    for (int i = 0; i < s.size(); i++) {
        if (i + p < s.size() && s[i] != s[i+p])
            return false;
    }
    return true;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	if (checkPeriod(s, p)) {
	    cout << "No\n";
	} else {
	    p--;
	    for (int i = 0;i < s.size(); i++) {
            if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
                s[i] = '0';
                s[i+p] = '1';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i] == '.') {
                if (s[i+p] == '0') s[i] = '1';
                else s[i] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i+p] == '.') {
                if (s[i] == '0') s[i+p] = '1';
                else s[i+p] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (!visited[i] && s[i] == '.') {
                s[i] = '0';
                visited[i] = true;
            }
	    }
	    cout << s << endl;
	}
	return 0;
}


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

bool checkPeriod(string s, int p) {
    bool same = false;
    int count = 0;
    int countDot = 0;
    for (int i = 0;i < s.size(); i++) {
        if (i + p < s.size() && s[i] == s[i+p]) {
            count++;
        }
        if (s[i] == '.') countDot++;
    }
    if (count == s.size() - p) same = true;
    if (countDot == s.size()) same = false;
    return same;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	if (checkPeriod(s, p) || (s.size() == 1 && p == 1)) {
	    cout << "No\n";
	} else {
	    for (int i = 0;i < s.size(); i++) {
            if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
                s[i] = '0';
                s[i+p] = '1';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i] == '.') {
                if (s[i+p] == '0') s[i] = '1';
                else s[i] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i+p] == '.') {
                if (s[i] == '0') s[i+p] = '1';
                else s[i+p] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (!visited[i] && s[i] == '.') {
                s[i] = '0';
                visited[i] = true;
            }
	    }
	    cout << s << endl;
	}
	return 0;
}


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

bool checkPeriod(string s, int p) {
    for (int i = 0; i < s.size(); i++) {
        if (i + p < s.size() && s[i] != s[i+p])
            return false;
    }
    int countDot = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') countDot++;
    }
    if (countDot == s.size()) return false;
    return true;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	if (checkPeriod(s, p) || (s.size() == 1 && p == 1)) {
	    cout << "No\n";
	} else {
	    if (p > 1) p--;
	    for (int i = 0;i < s.size(); i++) {
            if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
                s[i] = '0';
                s[i+p] = '1';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i] == '.') {
                if (s[i+p] == '0') s[i] = '1';
                else s[i] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i+p] == '.') {
                if (s[i] == '0') s[i+p] = '1';
                else s[i+p] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (!visited[i] && s[i] == '.') {
                s[i] = '0';
                visited[i] = true;
            }
	    }
	    cout << s << endl;
	}
	return 0;
}


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

bool checkPeriod(string s, int p) {
    bool same = false;
    int count = 0;
    for (int i = 0;i < s.size(); i++) {
        if (i + p < s.size() && s[i] == s[i+p]) {
            count++;
        }
    }
    if (count == s.size() - p) same = true;
    return same;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
    for (int i = 0;i < s.size(); i++) {
        if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
            s[i] = '0';
            s[i+p] = '1';
            visited[i] = true; visited[i+p] = true;
        } else if (i + p < s.size() && s[i] == '.') {
            if (s[i+p] == '0') s[i] = '1';
            else s[i] = '0';
            visited[i] = true; visited[i+p] = true;
        } else if (i + p < s.size() && s[i+p] == '.') {
            if (s[i] == '0') s[i+p] = '1';
            else s[i+p] = '0';
            visited[i] = true; visited[i+p] = true;
        } else if (!visited[i] && s[i] == '.') {
            s[i] = '0';
            visited[i] = true;
        }
    }
	if (checkPeriod(s, p)) cout << "No\n";
	else cout << s << endl;
	return 0;
}


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

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	bool impos = false;
	for (int i = 0;i < s.size(); i++) {
	    if (i + p < s.size() && s[i] == s[i+p]) {
	        impos = true;
	        break;
	    } else if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
	        s[i] = '0';
	        s[i+p] = '1';
	        visited[i] = true; visited[i+p] = true;
	    } else if (i + p < s.size() && s[i] == '.') {
	        if (s[i+p] == '0') s[i] = '1';
	        else s[i] = '0';
	        visited[i] = true; visited[i+p] = true;
	    } else if (i + p < s.size() && s[i+p] == '.') {
	        if (s[i] == '0') s[i+p] = '1';
	        else s[i+p] = '0';
	        visited[i] = true; visited[i+p] = true;
	    } else if (!visited[i] && s[i] == '.') {
	        s[i] = '0';
	        visited[i] = true;
	    }
	}
	if (impos) cout << "No\n";
	else cout << s << endl;
	return 0;
}


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

bool checkPeriod(string s, int p) {
    for (int i = 0; i < s.size(); i++) {
        if (i + p < s.size() && s[i] != s[i+p])
            return false;
    }
    int countDot = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '.') countDot++;
    }
    if (countDot == s.size()) return false;
    return true;
}

int main() {
	// your code goes here
	ios::sync_with_stdio(false); cin.tie(0);
	int n, p; cin >> n >> p;
	bool visited[n];
	memset(visited, false, sizeof visited);

	string s; getline(cin, s); getline(cin, s);
	if (checkPeriod(s, p) || (s.size() == 1 && p == 1)) {
	    cout << "No\n";
	} else {
	    for (int i = 0;i < s.size(); i++) {
            if (i + p < s.size() && s[i] == '.' && s[i+p] == '.') {
                s[i] = '0';
                s[i+p] = '1';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i] == '.') {
                if (s[i+p] == '0') s[i] = '1';
                else s[i] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (i + p < s.size() && s[i+p] == '.') {
                if (s[i] == '0') s[i+p] = '1';
                else s[i+p] = '0';
                visited[i] = true; visited[i+p] = true;
            } else if (!visited[i] && s[i] == '.') {
                s[i] = '0';
                visited[i] = true;
            }
	    }
	    cout << s << endl;
	}
	return 0;
}