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

using namespace std;


int main(){
    int team_point[101]={0};
    int point_rank[31]={0};
    
    int x,y;
    
    while(scanf("%d,%d",&x,&y)){
        if(x==0&&y==0)break;
        team_point[x]=y;
        int ran = 0;
        if(point_rank[y]!=0){
            for(int i=y; i>0; i--){
                if(point_rank[i]!=0){
                    ran = point_rank[i];
                    break;
                }
            }
            for(int i=y; i<31; i++){
                if(point_rank[i]!=0){
                    point_rank[i]++;
                    break;
                }
            }
        }
        point_rank[y]=ran+1;
    }
    int z;
    while(cin>>z){
        cout<<point_rank[team_point[z]]<<endl;
    }
    

}