#include <bits/stdc++.h>
using namespace std;
vector<long long> gpf(long long n) {
  vector<long long> v;
  while (n % 2 == 0) {
    v.push_back(2ll);
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      v.push_back(i);
      n = n / i;
    }
  }
  if (n > 2) v.push_back(n);
  return v;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(int a, int b) { return (a / gcd(a, b)) * b; }
bool prime(long long n) {
  if (n == 1)
    return 0;
  else if (n == 2)
    return 2;
  else {
    for (long long i = 2; i * i <= n; i++) {
      if (n % i == 0) {
        return i;
      }
    }
    return 0;
  }
}
string printBinary(long long n) {
  string s = "";
  while (n > 0) {
    s += to_string(n % 2);
    n /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
long long round(long long a, long long b) {
  if ((a * 1.0) / b == (long long)((a * 1.0) / b)) return a / b;
  return (a / b) + 1;
}
bool isp(long long x) { return x && (!(x & (x - 1))); }
long long roundn(long long x, long long n) {
  long long next = pow(n, ceil(log(x) / log(n)));
  if (next == x) return next;
  return next / n;
}
long long pw(long long x, long long n) { return ceil(log(x) / log(n)); }
int bs(int arr[], int p, int r, int num) {
  if (p <= r) {
    int mid = (p + r) / 2;
    if (arr[mid] == num) return mid;
    if (arr[mid] > num) return bs(arr, p, mid - 1, num);
    if (arr[mid] > num) return bs(arr, mid + 1, r, num);
  }
  return -1;
}
void solve(vector<int> &v, vector<int> &ans) {
  int mn = INT_MAX;
  int mnind = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] < mn) {
      mn = v[i];
      mnind = i;
    }
  }
  ans.push_back(mn);
  if (mnind == 0) {
    v.erase(v.begin() + 0);
    return;
  }
  int tt = v[mnind - 1];
  v.erase(v.begin() + mnind);
  int i = 0;
  while (i < v.size() && v[i] != tt) {
    ans.push_back(v[i]);
    i++;
  }
  i = 0;
  while (v[i] != tt) {
    v.erase(v.begin() + i);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    vector<int> ans;
    while (v.size() > 0) {
      solve(v, ans);
    }
    for (int c : ans) cout << c << " ";
    cout << "\n";
  }
}
