#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<pair<int, int> > t;
  int num, point, n;
  char dumy;
   
  while(cin >> num >> dumy >> point, num && point){
    t.push_back(make_pair(point, num));
  }
  
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  int ranking[t.size()], r = 1;
  
  for(int i = 0 ; i < t.size() ; i++){
    ranking[i] = r;
    if(t[i+1].first < t[i].first){
      r++;
    }
  }
  
  while(cin >> n){
    for(int i = 0 ; i < t.size() ; i++){
      if(t[i].second == n){
	cout << ranking[i] << endl;
	break;
      }
    }
  }
  return 0;
}