#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
const int N = 1e6 + 10; 
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int n, a[N], pos[N];
ll pw[N];
void solve()
{
    vector<int> res;
    int np = n;
    for(int i = n; i >= 1; -- i)
    {
        if(!pos[i]) continue;
        int tmp = pos[i];
        for(int j = pos[i]; j <= np; ++ j) {
            pos[a[j]] = 0;
            res.push_back(a[j]);
        }
        np = tmp - 1;
    }
    for(int &x:res)
    {
        cout << x << ' ';
    }
    cout << endl;
}
int main () {  
    fast;
    int t;
    cin >> t;
    while(t --)
    {
        cin >> n;
        for(int i = 1; i <= n; ++ i)
        {
            cin >> a[i];
            pos[a[i]] = i;
        }
        solve();
    }
    return 0;
}