#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll i,j,k,m,n,t,x;
   cin>>t;
   while(t--)
   {
       cin>>n;
       map<ll,ll>mymap;
       set<ll>myset;
       ll a[n+1];
       vector<ll>ans;
       for(i=1;i<=n;i++)
       {
           cin>>a[i];
           myset.insert(a[i]);
           mymap[a[i]]=i;
           //cout<<i<<" "<<mymap[a[i]]<<endl;
       }
       while(!myset.empty())
       {
           ll current_max = *myset.rbegin();
           ll current_max_index = mymap[current_max];
           //cout<<current_max<<" "<<current_max_index<<endl;
           for(ll i=current_max_index;i<=n;i++)
           {
              ans.push_back(a[i]);
              //cout<<a[i]<<endl;
              myset.erase(a[i]);
           }
           n=current_max_index-1;
           //cout<<"current size"<<n<<endl;
       }
       for(i=0;i<ans.size()-1;i++)
        cout<<ans[i]<<" ";
       cout<<ans[ans.size()-1]<<endl;

   }
}
