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

int a[100005], b[100005];

#define int long long int

int32_t main() {

        int t;cin >> t;
        while(t--) {
                int n; cin >> n;
                for(int i = 1; i <= n; i++) {
                        cin >> a[i];
                        b[a[i]] = i;
                }
                int m = n + 1;
                for(int i = n; i; i--) {
                        if(b[i] < m) {
                                for(int j = b[i]; j < m; j++) {
                                        cout << a[j] << " ";
                                }
                                m = b[i];
                        }
                }
                cout << endl;

        }
        return 0;
}