#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long a, long long b) {     a = a % mod;     long long ans = 1;     while (b > 0) {       if (b % 2 == 1) {         ans = (ans * a) % mod;       }       b = b / 2;       a = (a * a) % mod;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long loc[n + 1];       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         loc[a[i]] = i;       }       map<long long, long long> p;       long long m = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = loc[i]; j - 1 >= 0 && p[j - 1] == 0; j--) {           if (m > (n - 1)) {             break;           }           if (a[j - 1] > a[j]) {             swap(loc[a[j]], loc[a[j - 1]]);             swap(a[j], a[j - 1]);             p[j - 1]++;             m++;           } else {             break;           }         }       }       for (long long i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout << endl;     }   }   