#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, n, ent;
  cin >> q;
  while (q--) {
    cin >> n;
    vector<int> v(n);
    vector<int> pos(n + 1);
    int mark[n];
    for (int i = 0; i < n; i++) {
      cin >> ent;
      v[i] = ent;
      pos[ent] = i;
      mark[i] = 1;
    }
    int number = 1;
    int mov = 0;
    while (mov < n - 1 && number <= n) {
      if (pos[number] == 0)
        number++;
      else {
        if (v[pos[number]] < v[pos[number] - 1] && mark[pos[number] - 1]) {
          mark[pos[number] - 1] = 0;
          swap(v[pos[number]], v[pos[number] - 1]);
          swap(pos[number], pos[v[pos[number]]]);
          mov++;
        } else {
          number++;
        }
      }
    }
    for (int i = 0; i < n; i++) cout << v[i] << ' ';
  }
  return 0;
}
