#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int main(){ int N; cin>>N; vector> mp(N); map LCA; rep(i,N){ int m; cin>>m; rep(j,m){ int p,e; cin>>p>>e; mp[i][p] = e; LCA[p] = max(LCA[p],e); } } map pos; int cur = 0; vector ps(LCA.size()); for(auto a:LCA){ pos[a.first] = cur; ps[cur] = a.first; cur++; } set> S; rep(i,N){ vector t; for(auto a:mp[i]){ if(a.second == LCA[a.first]){ //cout< nt; rep(k,t.size()){ if((j>>k)&1)nt.push_back(t[k]); } S.insert(nt); } /* for(auto a:S){ rep(j,a.size()){ cout<> t(cur); rep(i,cur)t[i] = {i}; while(true){ if(t.size()==0){ cout<<-1<> nt; rep(i,t.size()){ int last = t[i].back(); for(int j=last+1;j temp = t[i]; temp.push_back(j); if(!S.count(temp)){ cout<> ans(temp.size()); rep(i,N){ rep(j,temp.size()){ if(mp[i].count(ps[temp[j]])&&mp[i][ps[temp[j]]]==LCA[ps[temp[j]]])continue; ans[j].push_back(i+1); break; } } rep(i,temp.size()){ rep(j,ans[i].size()){ if(j!=0)cout<<' '; cout<