#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    int t;cin>>t;
    while(t>0){
        t--;
        int n;cin>>n;
        vector<pair<int,int>>a;int b[n];
        for(int i=0;i<n;i++) {cin>>b[i]; a.push_back({b[i],i});}
        sort(a.begin(),a.end());
        vector<int>stop;
        stop.push_back(a[n-1].second);
        int current=a[n-1].second;
        for(int i=n-2;i>=0;i--){
          if(a[i].second<current) {stop.push_back(a[i].second);current=a[i].second;}
        }
        int last=n-1;
        for(auto x:stop){
            for(int i=x;i<=last;i++) cout<<b[i]<<" ";
            last=x-1;
        }
        cout<<endl;}}

