
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int n;
int a[N];
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
void write(int x)
{
if (x < 0)
putchar('-'), x = -x;
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
return;
}
struct
{
int parent;
int Left_child;
int Right_child;
} Binary_Tree[N];
int main()
{
n = read();
for (int i = 1; i <= n; i++)
{
Binary_Tree[i].parent = read();
if (Binary_Tree[Binary_Tree[i].parent].Left_child == 0)
Binary_Tree[Binary_Tree[i].parent].Left_child = i;
else
Binary_Tree[Binary_Tree[i].parent].Right_child = i;
}
for (int i = 1; i <= n; i++)
{
if (Binary_Tree[i].Left_child)
{
write(Binary_Tree[i].Left_child);
putchar(' ');
}
else
{
putchar('-1 ');
}
if (Binary_Tree[i].Right_child)
{
write(Binary_Tree[i].Right_child);
putchar(' ');
}
else
{
putchar('-1 ');
}
putchar('\n');
}
return 0;
}