#include using namespace std ; int main(){ int t ; cin >> t ; while( t-- ){ int n ; cin >> n ; vector > A(n+1) ; vector ans(n+1) ; for(int i=1;i<=n;i++){ int m ; cin >> m ; int x, y, tx, ty ; tx = INT_MIN ; while( m-- ){ cin >> x >> y ; tx = max(tx,x) ; } A[i].first = tx ; A[i].second = i ; } sort(A.begin()+1,A.end()) ; for(int i=1;i<=n;i++){ ans[A[i].second] = i ; } for(int i=1;i<=n;i++) cout << ans[i]-1 << " \n"[i == n] ; } return 0 ; }