# include <bits/stdc++.h>
# include <algorithm>
# include <stack>
using namespace std;
struct node
{
int data, place, next;
} z[100010];
int main()
{
int T;
while(~scanf("%d",&T))
{
while(T--)
{
int n;
scanf("%d",&n);
stack<struct node>Q;
int i;
for(i=0; i<n; i++)
{
scanf("%d",&z[i].data);
z[i].place=i;
z[i].next=-1;
if(Q.empty())
{
Q.push(z[i]);
}
else
{
while(!Q.empty())
{
struct node t=Q.top();
if(z[i].data>t.data)
{
z[t.place].next=z[i].data;
Q.pop();
}
else
break;
}
Q.push(z[i]);
}
}
for(i=0; i<n; i++)
printf("%d-->%d\n",z[i].data,z[i].next);
if(T!=0)
printf("\n");
}
}
return 0;
}
# include <algorithm>
# include <stack>
using namespace std;
struct node
{
int data, place, next;
} z[100010];
int main()
{
int T;
while(~scanf("%d",&T))
{
while(T--)
{
int n;
scanf("%d",&n);
stack<struct node>Q;
int i;
for(i=0; i<n; i++)
{
scanf("%d",&z[i].data);
z[i].place=i;
z[i].next=-1;
if(Q.empty())
{
Q.push(z[i]);
}
else
{
while(!Q.empty())
{
struct node t=Q.top();
if(z[i].data>t.data)
{
z[t.place].next=z[i].data;
Q.pop();
}
else
break;
}
Q.push(z[i]);
}
}
for(i=0; i<n; i++)
printf("%d-->%d\n",z[i].data,z[i].next);
if(T!=0)
printf("\n");
}
}
return 0;
}