#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> ans(n);
    map<int, int> m;
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      m[v[i]] = i;
    }
    int s = m[1];
    ans[0] = 1;
    if (s != 0) {
      ans[s] = v[s - 1];
      m[ans[m[1]]] = m[1];
      for (int i = 1; i < s; i++) {
        ans[i] = v[i - 1];
        m.erase(v[i - 1]);
      }
      v[s] = ans[s];
    } else {
      s++;
    }
    m.erase(1);
    while (s <= n - 1) {
      if (m.begin()->second == s) {
        ans[s] = m.begin()->first;
        m.erase(m.begin()->first);
        s++;
      } else {
        if (s == n - 1) {
          s += 1;
          continue;
        }
        int k = m.begin()->second;
        ans[s] = m.begin()->first;
        ans[k] = v[k - 1];
        m[v[k - 1]] = k;
        for (int i = s + 1; i < k; i++) {
          ans[i] = v[i - 1];
          m.erase(v[i - 1]);
        }
        v[k] = ans[k];
        m.erase(m.begin()->first);
        s = k;
      }
    }
    for (int i = 0; i < n; i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
