#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<pair<int, int> > team;
  int num, point, n;
  char dumy;
  int tcnt = 0;
  
  while(cin >> num >> dumy >> point, num && point){
    team.push_back(make_pair(point, num));
    tcnt++;
  }
  
  sort(team.begin(), team.end());
  reverse(team.begin(), team.end());
  
  int order[tcnt], j = 1;

  for(int i = 0 ; i < tcnt ; i++){
    order[i] = j;
    if(team[i+1].first < team[i].first) j++;
  }

  while(cin >> n){
    for(int i = 0 ; i < tcnt ; i++){
      if(team[i].second == n){
	cout << order[i] << endl;
	break;
      }
    }
  }
  return 0;
}