#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin>>N;
  
 
  
  for (int k=0;k<N;i++) {
    for (int j=0;j<N;j++) {
      vector<string> S(N);
      int P[j];
      cin>>S[j]>>P[j];
    }
    int sum[k]=1;
    
    for (int i=0;i<N;i++) {
      for (int j=0;j<S[i].size();j++) {
        int x=S[k].at(j)-'0'+48;
        int a=S[i].at(j)-'0'+48;
      
        if (x-a>=0) {
          continue;
        }
        else {
          sum[k]++;
        }
      }
      
      if (S[k]=S[i] && P[k]<P[i]) {
        sum[k]++;
      }
      else {
        continue;
      }
          
    }
    cout<<sum[k]<<endl;
  }
    
    
}