#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+10;
typedef long long ll;
int a[maxn];
pair<int, int> pi[maxn];

int main() {
    int t; scanf("%d", &t);
    while (t--) {
        int n; scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &pi[i].first);
            a[i] = pi[i].first;
            pi[i].second = i;
        }
        sort(pi+1, pi+1+n);
        int idx = 1e9;
        vector<int> ans;
        for (int i = n; i >= 1; i--) {
            if(pi[i].second < idx) {
                ans.push_back(pi[i].second);
                idx = pi[i].second;
            }
        }
        int pre = n;
        for (int i = 0; i < ans.size(); i++) {
            int now = ans[i];
            //cout << now << "?\n";
            while(now <= pre) {
                printf("%d ", a[now]);
                now++;
            }
            pre = ans[i] - 1;
        }
        printf("\n");
    }
    return 0;
}