#include "bits/stdc++.h"

#define ll long long int
#define MOD 1000000007
using namespace std;


ll randNum(ll a , ll b){
	return a + rand() % (b-a+1);
}

template<class t>
void print(t *a , int n){
	for(int i =0 ; i<n ; i++) cout<<a[i]<<" ";
	cout<<endl;
}

template<class t>
void print(vector<t> &v){
	for(int i=0 ; i<v.size() ; i++)	cout<<v[i]<<" ";
	cout<<endl;
}


ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}


ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}


ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
   
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll modInverse(ll b, ll m) 
{ 
    ll x, y;
    ll g = gcdExtended(b, m, &x, &y); 
  
    if (g != 1) 
        return -1; 
  
    return (x%m + m) % m; 
} 
  
ll modDivide(ll a, ll b, ll m) 
{ 
    a = a % m; 
    ll inv = modInverse(b, m); 
    if (inv == -1) 
       return -1; 
    else
       return (inv * a) % m; 
} 

//precompute factorial array if multiple queries are present
unsigned long long nCrModPFermat(unsigned long long n, int r, int p){
	
    if (n < (unsigned long long)r)
        return 0;
    if (r == 0)
        return 1;
 
    unsigned long long fac[n + 1];
    fac[0] = 1;
    for (unsigned long long i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;
 
    return (fac[n] * modInverse(fac[r], p) % p
            * modInverse(fac[n - r], p) % p)
           % p;
}
  
  
//--------


void testcase(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0 ; i<n ; i++) cin>>v[i];
	vector<int> prevmax(n) , prevmaxindex(n);
	prevmax[0] = v[0];
	prevmaxindex[0] = 0;
	for(int i=1 ; i<n ; i++) {
		if(v[i] > prevmax[i-1]){
			prevmax[i] = v[i];
			prevmaxindex[i] = i;
		}
		else{
			prevmax[i] = prevmax[i-1];
			prevmaxindex[i] = prevmaxindex[i-1];
		}
		//prevmax[i] = max(v[i] , prevmax[i-1]);
	}
	
	int end = n-1;
	vector<int> ansindex;
	while(end >= 0){
		int index = prevmaxindex[end];
		ansindex.push_back(index);
		end = index-1;
	}
	
	for(int i=0 ; i<ansindex.size() ; i++){
		if(i == 0){
			for(int j=ansindex[i] ; j<n ; j++) cout<<v[j]<<' ';
		}
		else{
			for(int j = ansindex[i] ; j<ansindex[i-1] ; j++) cout<<v[j]<<' ';
		}
	}
	cout<<endl;
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int tt;
    cin>>tt;
    tt++;
    while(--tt){
        testcase();
    }
    return 0;
    
}
