#include <bits/stdc++.h>
using namespace std;
long long int my_pow(long long int x) {
  long long int ret = 1ll, i;
  for (i = 1ll; i <= x; i++) ret *= 2ll;
  return ret;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, i, j, k, l, m, pos, pos1, cc = 0, full = 0;
    cin >> n;
    int arr[n + 1], arr1[n + 1], ind[n + 1];
    memset(arr1, 0, sizeof arr1);
    for (i = 1; i <= n; i++) cin >> arr[i], ind[arr[i]] = i;
    for (i = 1; i <= n; i++) {
      if (ind[i] > full) {
        for (j = ind[i]; j - 1 > full; j--) {
          arr[j] = arr[j - 1], ind[arr[j]] = j;
        }
        if (j == ind[i])
          full = j;
        else
          arr[j] = i, full = ind[i] - 1, ind[i] = j;
      }
    }
    for (i = 1; i <= n; i++) {
      cout << arr[i];
      if (i == n)
        cout << endl;
      else
        cout << " ";
    }
  }
  return 0;
}
