#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> perm;
    int pos[n + 1];
    for (int i = 0; i < n; i++) {
      int u;
      cin >> u;
      perm.push_back(u);
      pos[u] = i;
    }
    int imp = 0;
    int i = 1;
    while (i < n && imp <= n - 2) {
      if (pos[i] > imp) {
        int old = imp;
        imp = pos[i];
        pos[perm[pos[i] - 1]] = imp;
        perm.erase(perm.begin() + imp);
        perm.insert(perm.begin() + old, i);
      } else if (pos[i] == imp)
        imp++;
      i++;
    }
    for (int i = 0; i < n; i++) cout << perm[i] << " ";
    cout << endl;
  }
}
