#include <iostream>
#include <vector>
#include <map>
using namespace std;

typedef vector<pair<int, int> > PV;

int main(){
	PV ranking;

	while(true){
		int num, score;
		scanf("%d,%d", &num, &score);
		if(!(num || score)) break;
		ranking.push_back( pair<int, int>(num, score) );
	}
	
	int n = ranking.size();
	for(int i=n;i>0;--i){
		for(int j=0;j<n-1;++j){
			if(ranking[j].second < ranking[j+1].second)
				ranking[j].swap(ranking[j+1]);
		}
	}
	
	PV res;
	int currentRank = 1;
	int bufScore = ranking[0].second;
	for(int i=0;i<n;++i){
		if(ranking[i].second < bufScore){
			currentRank++;
			bufScore = ranking[i].second;
		}
		
		res.push_back( pair<int, int>(ranking[i].first, currentRank) );
	}

	int input;
	while(cin >> input){
		for(int i=0;i<n;++i){
			if(res[i].first == input){
				cout << res[i].second << endl;
				break;
			}
		}
	}
}