#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <list>
#include <stdio.h>

using namespace std;


int main(){
    
    
    int x,y;
    int team[101]={0};
    int point[31]={0};
    while(scanf("%d,%d",&x,&y)){
        if(x==0&&y==0)break;
        team[x]=y;
        point[y]=y;
    }
    sort(point, point+31);
    int z;
    while(scanf("%d",&z)!=EOF){
        for(int i=30; i>=0; i--){
            if(point[i]==team[z]){
                cout<<31-i<<endl;
            }
        }
    }
    
    //for(int i=0; i<=30; i++)cout<<i<<" : "<<point[i]<<endl;
    
    
}