#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    vector<int> arr(n + 1), pos(n + 1);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &arr[i]);
      pos[arr[i]] = i;
    }
    int q = n - 1;
    set<int> s;
    for (int id = 1; id < n; id++) {
      for (int i = pos[id]; i > id and q; i--) {
        if (s.find(i - 1) != s.end() or arr[i] > arr[i - 1]) break;
        q--;
        s.insert(i - 1);
        swap(arr[i], arr[i - 1]);
        swap(pos[arr[i]], pos[arr[i - 1]]);
      }
    }
    for (int i = 1; i <= n; i++) printf("%d ", arr[i]);
    puts("");
  }
}
