// Author: Cvangi
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
#define ll long long int
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
#define debug(x) cout<<#x<<" "<<x<<endl;
#define debug1(x,y,z) cout<<#x<<" "<<x<<endl<<#y<<" "<<y<<endl<<#z<<" "<<z<<endl;
#define pi 3.1415926535897932384626433832
#define pp pair<int,int>
#define fi first
#define se second
 
 
using namespace std;
 
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b);
unsigned ll gcd(unsigned ll a, unsigned ll b) ;
 int prime(ll n);
ll power(ll x,ll y);
ll nCr(ll n,ll r,ll p);
 
ll sum(ll n){
return (n*(n+1))/2;
}
 
void solve(){
    ll n;
    cin>>n;
    ll a[n];
    unordered_map<ll,ll>m;
    f(i,n){
        cin>>a[i];
        m[a[i]]=i;
    }
    int ind=n;
    for(int i=n;i>0;){
        while(i>0&&m[i]>=ind)i--;
        if(i==0){
            cout<<endl;
            return;
        }
        for(int j=m[i];j<ind;j++){
            cout<<a[j]<<" ";
        }
        ind=m[i];
    }
    cout<<endl;
}
 
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll t=1,p=0;
        cin>>t;
 
 
 
 
    while(t--&&++p){
        // cout<<"Case #"<<p<<": ";
        solve();
}
}
 
 
 
 
 
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
unsigned ll gcd(unsigned ll a, unsigned ll b) {
    if(a==1||b==1)return 1;
    if (b == 0) return a;
    return gcd(b, a % b);
}
int prime(ll n){
    int flag=1;
for(ll i=2;i<=sqrt(n);i++){
    if(n%i==0){flag=0;break;}
}
  return flag;
}
ll power(ll x,ll y)
{
    ll temp;
    if( y == 0)
        return 1;
    temp = power(x, y/2)%mod;
    if (y%2 == 0)
        return (temp*temp)%mod;
    else
        return (((x*temp)%mod)*temp)%mod;
}
ll nCr(ll n, ll r, ll p) 
{ 
    if (r > n - r) 
        r = n - r; 

    ll C[r + 1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;
  
    for (ll i = 1; i <= n; i++) { 
  
        for (ll j = min(i, r); j > 0; j--) 
  
            
            C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
} 