#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> p(n + 1);
    vector<bool> used(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      p[a[i]] = i;
    }
    for (int i = 1; i <= n; i++) {
      int j = p[i];
      while (j > 0 && !used[j - 1] && a[j] < a[j - 1]) {
        p[i]--;
        p[a[j - 1]]++;
        swap(a[j], a[j - 1]);
        used[j - 1] = true;
        j--;
      }
    }
    for (int i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
