unittest
{
	assert( [ "3", "1 2 1" ].parse.expand.solve == "1\n1\n2" );
	assert( [ "2", "2 2" ].parse.expand.solve == "-1" );
	assert( [ "9", "1 1 1 2 2 1 2 3 2" ].parse.expand.solve == "1\n2\n2\n3\n1\n2\n2\n1\n1" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	return tuple( bs );
}

auto solve( long[] bs )
{
	auto ans = solve2( bs );
	return ( !ans.empty ) ? ans.to!( string[] ).join( "\n" ) : "-1";
}

long[] solve2( long[] bs )
{
	static long[][ long[] ] memo;
	
	if( bs.length == 1 ) return ( bs[ 0 ] == 1 ) ? bs : [];
	
	if( bs in memo ) return memo[ bs ];
	
	for( auto j = bs.length; 0 < j; j-- )
	{
		if( bs[ j - 1 ] != j ) continue;
		auto as = solve2( bs[ 0 .. j - 1 ] ~ bs[ j .. $ ] );
		if( !as.empty ) return memo[ bs.idup ] = as ~ bs[ j - 1 ];
	}
	return memo[ bs.idup ] = [];
}
