#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>

using namespace std;


int main(){
  int id,solved;
  vector<int> VVV;//フェーフェーフェーフェンロ
  vector<int> info[40];
  while(true){
    scanf("%d,%d",&id,&solved);
    if(id + solved == 0)break;
    VVV.push_back(solved);
    info[id].push_back(solved);
  }
  sort(VVV.begin(),VVV.end(),greater<int>() );

  int rank[100],cnt=1,now=VVV[0];
  for(int i=0;i<VVV.size();i++){
      if(VVV[i] == now){
	rank[now] = cnt;
      }      
      else if(VVV[now] != now){
	cnt++;
	now = VVV[i];
	rank[now] = cnt;
      }
    }
	int exec;
      while(cin >> exec){
	cout << rank[info[exec][0]] << endl;
      }	


  return 0;
}