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

typedef pair<int, int> pi;

bool cmp(pi lhs, pi rhs)
{
	return (lhs.second > rhs.second);
}

int main()
{
	int n, a;
	int c;
	vector <pi> p(100);
	
	for (int i = 0; n != 0 || a != 0; i++){
		scanf("%d,%d", &n, &a);
		p[i] = make_pair(n, a);
		c = i;
	}
	
	sort(p.begin(), p.end(), cmp);
	
	int pin = 31, minnum = 0;
	for (int i = 0; i < c; i++){
		if (pin == p[i].second){
			p[i].second = minnum;
		}
		
		else if (pin > p[i].second){
			pin = p[i].second;
			minnum++;
			p[i].second = minnum;
		}
	}
	
	int team;
	while (scanf("%d", &team) != EOF){
		cout << p[team].second << endl;
	}
	return (0);
}