#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

typedef	pair<int,int> pii;

int main()
{
	vector<pii> data;
	int id_max=0;
	for(int i=0;;i++){
		int id,score;
		id_max=max(id_max,id);
		scanf("%d,%d",&id,&score);
		if(id==0&&score==0)	break;
		data.push_back(make_pair(score,id));
	}

	sort(data.begin(),data.end(),greater<pii>());

	vector<int> rank(id_max);
	rank[data[0].second]=1;
	int score_bef=data[0].first;
	for(int i=1,r=1;i<data.size();i++){
		if(data[i].first<score_bef)	r++;
		rank[data[i].second]=r;
		score_bef=data[i].first;
	}

	int n;
	while(~scanf("%d",&n))printf("%d\n",rank[n]);

	return 0;
}