#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
using graph = vector<vi>;
using matrix = graph;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INFL = 1e18 + 4;
const ll mod = 1e9 + 7;
int p[MAXN], pos[MAXN], done[MAXN];
int main() {
  int q;
  scanf("%d", &q);
  int n;
  while (q--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", p + i);
      pos[p[i]] = i;
      done[i] = 0;
    }
    int nxt = 1;
    while (nxt < n) {
      while (pos[nxt] != nxt && done[pos[nxt] - 1] == 0 &&
             p[pos[nxt] - 1] > nxt) {
        done[pos[nxt] - 1] = 1;
        swap(p[pos[nxt]], p[pos[nxt] - 1]);
        pos[p[pos[nxt]]]++;
        pos[nxt]--;
      }
      nxt++;
    }
    for (int i = 1; i <= n; ++i) {
      printf("%d%c", p[i], i == n ? '\n' : ' ');
    }
  }
}
