#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<cstdio>
#include<cmath>
#include<stdlib.h>

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+50;
int a[maxn];
int maxs[maxn];
int main(){
	int T;
	cin >> T;
	while(T--){
		int n;
		scanf("%d",&n);
		map<int,int>mp; 
		for(int i = 1;i <= n;i++){
			maxs[i] = 0;
			scanf("%d",&a[i]);
			maxs[i] = max(maxs[i-1],a[i]);
			mp[a[i]] = i;
		}
		int rec = n;//[re_max,rec]
		while(rec > 0){
			int t = maxs[rec];
			t = mp[t];//前rec的最大值的位置 
			for(int i = t;i <= rec;i++)		printf("%d ",a[i]);
			rec = t-1; 
		}
		puts("");
	}
	return 0;
}
