#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
void solve()
{
    int n,start=0;
    cin>>n;
    int end=n;
    int arr[n],pos[n+1];
    for(int i=0 ; i<n;i++)
    {
    cin>>arr[i];
    pos[arr[i]]=i;
    }
    for(int i=n;i>0;i--)
    {
        start = pos[i];
        if(end>start)
        {
            for(int j=start ; j<end ; j++)
            {
                cout<<arr[j]<<" ";
            }
        end = start;
        }
    }
    cout<<endl;
}

int main()
{
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}