#include <cstdio>
#include <vector>
using namespace std;

int main(){
	vector<int> score[31];
	vector<int> rank[101];
	int n, s, r;
	
	while(true){
		scanf("%d,%d", &n, &s);
		
		if(n == 0 && s == 0) break;
		
		score[s].push_back(n);
	}
	
	r = 0;
	for(int i = 30; i > 0; i--){
		if(score[i].empty()) continue;
		
		r++;
		for(int j = 0; j < score[i].size(); j++){
			rank[r].push_back(score[i][j]);
		}
	}
	
	while((scanf("%d", &n)) != EOF){
		//printf("a\n");
		
		for(int i = 1; i <= 100; i++){
			if(rank[i].empty()) continue;
			
			for(int j = 0; j < rank[i].size(); j++){
				if(n == rank[i][j]){
					printf("%d\n", i);
				}
			}
		}
	}
	
	return 0;
}