#include #include using namespace std; using namespace atcoder; typedef long long int ll; typedef long double ld; #define FOR(i,l,r) for(ll i=l;i=l;i--) #define RREP(i,n) RFOR(i,0,n) #define ALL(x) x.begin(),x.end() #define P pair #define F first #define S second #define BS(A,x) binary_search(ALL(A),x) #define LB(A,x) (ll)(lower_bound(ALL(A),x)-A.begin()) #define UB(A,x) (ll)(upper_bound(ALL(A),x)-A.begin()) #define COU(A,x) UB(A,x)-LB(A,x) templateusing min_priority_queue=priority_queue,greater>; //using mint=modint1000000007; using mint=modint998244353; signed main(){ ll N;cin>>N; vectorA(N,1); vector>X(N); setprime; REP(i,N){ ll m;cin>>m; REP(j,m){ ll p,e;cin>>p>>e;prime.insert(p);X[i].push_back(P(p,e));A[i]*=pow(p,e); } } ll K=prime.size();vectorp;for(auto i:prime)p.push_back(i);vectorMAX(K); REP(i,N)REP(j,X[i].size())MAX[LB(p,X[i][j].F)]=max(MAX[LB(p,X[i][j].F)],X[i][j].S); vector>Q(N),R(K); REP(i,N)REP(j,X[i].size())if(MAX[LB(p,X[i][j].F)]==X[i][j].S)Q[i].push_back(LB(p,X[i][j].F)); REP(i,N)if(Q[i].size()==K){cout<<-1<XX(K); REP(i,k)XX[i]=1;sort(ALL(X)); do{ setT; REP(i,K)if(XX[i]){ if(T.size()==0)for(ll j:R[i])T.insert(j); else for(ll j:T)if(!binary_search(ALL(R[i]),j))T.erase(T.find(j)); } if(T.size()==0){ cout<TT(N,1); REP(i,K)if(XX[i]){ vectorans; REP(j,N)if(!binary_search(ALL(R[i]),j)&&TT[j]){TT[j]=0;ans.push_back(j);} cout<