#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<cstdio>
using namespace std;

int main(){

  int a,b,t,s,ans[1000],n = 0;
  vector < pair < int, int > > p;

  while(true){
    scanf("%d,%d",&a,&b);
    if(!a && !b) break;
    
    pair < int, int > P(b,a);

    p.push_back(P);
    n++;
  }

  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  

  t = 1;
  for(int i=0;i<n-1;i++){
    if(p[i].first == p[i+1].first) ans[i] = t;
    else{
      t++;
      ans[i] = t;
    }
  }

  while(cin >> s) cout << ans[s-1] << endl;
}