/* GCC */

#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

int n;
vector<queue<int> > all;

int main()
{
    freopen("graph.in", "r", stdin);
    freopen("graph.out", "w", stdout);

    scanf("%d\n", &n);

    for (int v = 1; v <= n; v++)
    {
        queue<int> adj;
        int num = 0;
        while (true)
        {
            char c;
            scanf("%c", &c);
            if (c >= '0' && c <= '9')
                num = num * 10 + (c - '0');
            else
            {
                if (num > v)
                    printf("%d %d\n", v, num);
                num = 0;
            }
            if (c == '\n')
                break;
        }
    }

    return 0;
}
