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

/*
    
*/

#define pb push_back
#define forn(i, l, r) for(int i = l; i <= r; i++)
#define fornr(i, r, l) for(int i = r; i >= l; i--)
#define INF 1000000000
#define x real()
#define y imag()
#define M_PI 3.14159265358979323846
typedef double T;
typedef complex<T> pt;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
inline istream& skip_endl(istream &is) { return is.ignore(numeric_limits<streamsize>::max(),'\n'); }

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t, n;
    cin >> t;
    while(t--) {
        cin >> n;
        vii v(n);
        vi vv(n);
        forn(i, 0, n - 1) {
            cin >> v[i].first;
            vv[i] = v[i].first;
            v[i].second = i;
        }

        sort(v.begin(), v.end(), greater<ii>());
        int max_idx = n - 1, i = 0, curr_bound = n - 1;
        while(true) {
            max_idx = v[i].second;
            if(max_idx > curr_bound) {
                i++;
                continue;
            }
            forn(j, max_idx, curr_bound) {
                cout << vv[j] << " ";
            }
            curr_bound = max_idx - 1;
            i++;
            if(curr_bound < 0) break;
        }
        cout << "\n";
    }
    return 0;
}