include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 200010;
int n;
int p[N], q[N];
bool st[N];
int main()
{
int T;
scanf(“%d”,&T);
while(T – )
{
scanf(“%d”,&n);
memset(q, 0, sizeof q);
memset(st, 0, sizeof st);
for (int i = 1; i <=n; i ++)
{
scanf(“%d”,&p[i]);
q[p[i]] = i;
}
bool flag = false;
for (int i = 1; i <= n; i++)
{
if(st[i] || !p[i]) continue;
st[i] = true;
int x = i, y = i;
while (p[x] && !st[p[x]])
{
x = p[x];
st[x] = true;
}
while (q[y] && !st[p[x]])
{
y = q[y];
st[y] = true;
}
if(p[x] == y) continue;
if(!flag)
{
flag = true;
for (int j = 1; j <= n; j++)
if(!p[j] && !q[j])
{
st[j] = true;
p[x] = j;
x = j;
}
}
p[x] = y;
}
for (int i = 1; i <= n; i ++)
printf("%d", p[i]);
puts("");
}
return 0;
}