// V T An
#include <bits/stdc++.h>
#define Task "CF"
#define ll long long
#define F first
#define S second
#define pb push_back
#define MOD 1000000007

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef pair<int, int> pii;

const int maxn = 200005;
const int oo = 2e9;

int n, p[maxn];
int cnt[maxn];

void Solve(int T) {
  cin >> n;
  for(int i = 1; i <= n; ++ i) cin >> p[i], cnt[p[i]] = 0;
  int j = n, maxx = n;
  for(int i = n; i >= 1; -- i) {
    while(cnt[maxx]) -- maxx;
    cnt[p[i]] = 1;
    if(p[i] == maxx) {
      for(int k = i; k <= j; ++ k) {
        cout << p[k] << " ";
        cnt[p[k]] = 1;
      }
      j = i - 1;
    }
  }
  cout << "\n";
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  if(fopen(Task".inp", "r")) {
    freopen(Task".inp", "r", stdin);
    freopen(Task".out", "w", stdout);
  }
  int test = 1;
  cin >> test;
  for(int i = 1; i <= test; ++ i) {
    Solve(i);
  }
}

// CHY - AKAV
