#include <iostream>
#include <map>
using namespace std;
int main()
{
	map<int,int> data;
	bool score[31];
	while(1)
	{
		int temp1,temp2;
		cin >> temp1 ; cin.ignore() ; cin >> temp2 ;
		if(temp1==0 && temp2==0) break;
		data[temp1]=temp2;
		score[temp2]=true;
	}
	int rank[31];
	int n=1;
	for(int i=30;i>=0;i--)
		if(score[i]==true) rank[i]=n++;
	int num;
	while(cin >> num) cout << rank[data[num]] << endl ;
}