#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compar(const int *val1, const int *val2);
#define N 100
int main(void){
	int n,m,i,j,z,A[N],B[N],C[1000],cnt=0,tmp;
	char s[N],str[N],*line;

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		line=strtok(str," ,");
		sscanf(line,"%d",&m);	
		line=strtok(NULL," ,");	
		sscanf(line,"%d",&n);
		if(m==0 && n==0)
			break;
		A[m]=n;
		B[m]=n;
		cnt++;
	}
	for(i=1;i<=cnt;i++){
		for(j=cnt;j>i;j--){	
			if(B[j] > B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
	j=0; B[0]=0;
	for(i=0;i<cnt;i++){
		if(B[i]!=B[i+1])
			C[B[i]]=j++;
		else
			C[B[i]]=j;
	}
	for( ;fgets(s,sizeof(str),stdin)!=NULL; ){
		sscanf(s,"%d",&z);	
		printf("%d\n",C[A[z]]);
	}
	return 0;
}