#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
template <typename T>
inline bool Maximize(T& Target, T Value);
template <typename T>
inline bool Minimize(T& Target, T Value);

using namespace std;
using lli = long long;
const int maxN = 1e5;
int n;
int p[maxN], maxid[maxN], q[maxN];

void ReadInput()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> p[i];
}

void Solve()
{
    maxid[0] = 0;
    for (int i = 1; i < n; ++i)
        if (p[i] > p[maxid[i - 1]])
            maxid[i] = i;
        else
            maxid[i] = maxid[i - 1];
    int Pos = n, qid = 0;
    while (Pos > 0)
    {
        int i = maxid[Pos - 1];
        copy(p + i, p + Pos, q + qid);
        qid += Pos - i;
        Pos = i;
    }
    for (int i = 0; i < n; ++i)
        cout << q[i] << ' ';
    cout << '\n';
}

int main()
{
    #ifndef cfc
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #else
    freopen("input.txt", "r", stdin);
    #endif // cfc
    int ntests;
    cin >> ntests;
    while (ntests-- > 0)
    {
        ReadInput();
        Solve();
    }
}

template <typename T>
inline bool Maximize(T& Target, T Value)
{
    if (Value > Target)
    {
        Target = Value;
        return true;
    }
    return false;
}

template <typename T>
inline bool Minimize(T& Target, T Value)
{
    if (Value < Target)
    {
        Target = Value;
        return true;
    }
    return false;
}
