#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int p[n+1],b[n+1],a[n+1];
		bool v[n+1];
		memset(v,false,sizeof(v));
		for(int i=1;i<=n;i++){
			cin>>p[i];
			b[p[i]]=i;
		}
		int k=1;
		for(int i=n;i>0;i--){
			int j=b[i];
			while(j<=n && v[j]!=1){
				v[j]=1;
				a[k]=p[j];
				k++;
				j++;
			}
		}
		for(int i=1;i<=n;i++)cout<<a[i]<<" ";
		cout<<"\n";
	}
	return 0;
}

