#include<algorithm>
#include<iostream>
#include<string>
#include <bits/stdc++.h> 
#define ll long long
//Use float when we have to claculate digit after decimal.

using namespace std;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        int arr[n];
        vector<int> vec,vec1,vec2;
        for(int i=0; i<n; i++)
        {
            cin>>arr[i];
            ll temp = arr[i];
            vec.push_back(temp);
        }
        ll oop=0;
        for(int i=0; i<n; i++)
        {
            if(vec[i]>oop)
            {
                oop=vec[i];
                vec1.push_back(i);
            }
            else
            {
                continue;
            }
        }
        
        
        for(int i=vec1.size()-1; i>=0; i--)
        {
            ll xd=vec.size()-vec1[i];
            for(int j=vec1[i]; j<vec.size(); j++)
            {
                cout<<vec[j]<<" ";
            }
            for(int k=0; k<xd; k++)
            {
                vec.pop_back();
            }
            
        }
        


        
       
        

        
        cout<<"\n";
    }

    return 0;
}