#include<bits/stdc++.h
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int N = 200005;
int anc[N];
int find(int x) {
return anc[x] == x ? x : anc[x] = find(anc[x]);
}
void solve() {
int n;
cin >> n;
std::vector<std::vector<int>> o(n + 1);
for(int i = 1;i <= n;++i) {
int c; cin >> c;
o[i].resize(c);
for(int & x : o[i]) cin >> x;
}
std::vector<std::pair<int, int>> ans;
for(int i = n;i >= 1;--i) {
anc[i] = i;
for(int y : o[i]) {
int z = find(y);
ans.emplace_back(i, z);
anc[z] = i;
}
}
for(auto [x, y] : ans) {
cout << x << ' ' << y << '\n';
}
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
int t;
cin >> t;
while(t--) {
solve();
}
}