#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std;



int main(){
	int a,b,score[101],point[30],i;
	for( i=0;i<30;i++) point[i] = -1;
	while(1){
		scanf("%d,%d",&a,&b);
		score[a] = b;
		for(i=0;point[i]!=-1;i++){
			if(point[i] == b)break;
		}
		point[i] = b;				
		if(a==0&&b==0) break;
	}
	
	for(i=0;i<101;i++){
		for(int j=1;j<101-i;j++){
			if(point[i-1]<point[i]){
				b=point[i];
				point[i]=point[i-1];
				point[i-1]=b;
			}
		}
	}
	
	while( scanf("%d",&a) != EOF){
		for(i=0;point[i]!=-1;i++){
			if(score[a] == point[i])break;
		}
		printf("%d\n",i+1);
	}
			
	return 0;
}
