#include <algorithm>
using namespace std;

int main(void){
  pair<int,int> p[101];
  int num,point,i = 0;
  char cm; 
 
  while(1){
    cin >> num >> cm >> point;
    if(num == 0 && point == 0) break;
    
    p[i] = make_pair(-point,num);
    i++;
  }

  sort(p,p+i);
  
  int key;
  while(cin >> key){
    int cnt = 1;
    for(int j = 1 ; p[j].second!=key ; j++){
      if((-1)*p[j].first != (-1)*p[j-1].first) cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}