#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> index(n + 1);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      index[v[i]] = i;
    }
    bool a[n];
    for (int i = 0; i < n; i++) a[i] = true;
    a[0] = false;
    for (int i = 1; i <= n; i++) {
      if (a[index[i]]) {
        for (int j = index[i]; j > 0; j--) {
          if (a[j]) {
            if (v[j] < v[j - 1]) {
              a[j] = false;
              swap(v[j], v[j - 1]);
            }
          } else
            break;
        }
      }
    }
    for (auto i : v) cout << i << " ";
    cout << endl;
  }
}
