#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
//#include <map>
#include <iomanip>
#include <vector>

using namespace std;



int main()
{
	vector<int> res[31];
	int bango, seikaisu;
	int rank = 0;
	int juni[101];
	int toi;
	
	while (scanf("%d,%d", &bango, &seikaisu))
	{
		if (bango == 0 && seikaisu == 0) break;
		res[seikaisu].push_back(bango);
	}
	for (int i=30; i>=1; i--)
	{
		if (res[i].size() > 0)
		{
			rank++;
			for (int j=0; j<res[i].size(); j++)
			{
				juni[res[i][j]] = rank;
			}
		}
	}
	
	while (cin >> toi)
	{
		cout << juni[toi] << endl;
	}
	
	return 0;
}