#include <bits/stdc++.h>
using namespace std;
int a[1000006];
int b[1000006];
int sta[100006];
int main()
{
int t,n,i,j,top;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
for( i = 1; i <= n; i ++)
{
scanf("%d", &a[i]);
}
top = 0;
b[n] = -1;
for(i = n - 1; i >= 1; i --)
{
if(a[i + 1] > a[i])
{
b[i] = a[i + 1];
sta[top ++] = b[i];
// cout << "sta[top] = "<< sta[top - 1] << endl;
}
else {
int f = 1;
while(top)
{
// cout << "top = " <<top << endl;
if(sta[top - 1] > a[i])
{
b[i] = sta[top - 1];
f = 0;
break;
}
top --;
}
if(top == 0 || f == 1) b[i] = -1;
}
}
for(i = 1; i <= n; i ++)
{
printf("%d-->%d
",a[i],b[i]);
}
if(t != 0) printf("
");
}
}
return 0;
}