#include<bits/stdc++.h>
using namespace std;
int t,n,a[100010],id[100010],l,r;
set<int> s;
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	t=read();
	while (t--)
	{
		n=read();
		for (int i=1;i<=n;++i)
		{
			a[i]=read();
			id[a[i]]=i;
			s.insert(-a[i]);
		}
		r=n;
		while (r)
		{
			l=id[-(*s.upper_bound(-n-1))];
			for (int i=l;i<=r;++i)
			{
				printf("%d",a[i]);
				if (l==1&&i==r) printf("\n");
				else printf(" ");
				s.erase(-a[i]);
			}
			r=l-1;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
