#include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;
int main (void){

  int  a ,b[MAX] , jun[31] , temp[MAX] , b2[MAX];
  char c[MAX];
  int i = 0;
  int j = 1 ;
  int stop;
  while (1){




    cin >> a   >> c[a] >> b[a];

    b2[a] = b[a];
    

    if ( a == 0 && b[a] == 0) break;

    

    i++;

    }

  stop = i - 1;
  

  sort( b , b + (i - 1) );
  
  
  for (int i = 1 ; i < stop ; i++){


    temp[i] = b[stop - i ]; 



  }

  for(int i = 1 ; i < stop ; i++){

  
    b[i] = temp[i];


  

  }


  for(int i = 1; i < stop  ; i++){

 
    if( i < stop - 1){

    if( b[i] != b[i + 1]  ) jun[ b[i] ] = j++;
    else  continue;

    }

   
    jun[ b[i] ] = j++;


  }




  

  while ( cin >> i){


    cout << jun[b2[i]] - 2<<endl  ;



  }
  


  return 0;
}