#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>

#define ll long long
#define test(t) ll int t; cin>>t; while(t--)
#define F(i,L,R) for(ll int i=L;i<R;i++)
#define F2(i,L,R) for(ll int i=L;i>=R;i--)
#define get1(a) ll int a; cin>>a;
#define get2(a,b) ll int a,b; cin>>a>>b;
#define get3(a,b,c) ll int a,b,c; cin>>a>>b>>c;
#define pb push_back
#define mp make_pair
#define MAX 1000000001
using namespace std;



int main()
{ 
 

 ios_base::sync_with_stdio(0);

 #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 #endif

 test(t)
 {
 	 get1(n);

 	 vector<ll int> v(n,-1);
 	 vector<ll int> max_till_here(n,-1);
 	 unordered_map<ll int,ll int> index;
 	 ll int curr_max=-1;
 	 F(i,0,n)
 	 {
 	 	cin>>v[i];
 	 	curr_max=max(curr_max,v[i]);
 	 	max_till_here[i]=curr_max;

 	 	index[v[i]]=i;

 	 }


 	 ll int curr=n-1;

 	 vector<ll int> res;

 	 while(curr>=0)
 	 {
 	 	ll int val=max_till_here[curr];

 	 	ll int in=index[val];

 	 	F(i,in,curr+1)
 	 	{
 	 		res.push_back(v[i]);
 	 	}
 	 	curr=in-1;
 	 }

 	 for(auto it: res)
 	 {
 	 	cout<<it<<" ";
 	 }
 	 cout<<"\n";
 }
  return 0;
 
}