#include<iostream>
#include<set>
#include<cstdio>
using namespace std;
int main() {
	int a, b;
	set<int> c;
	int d[101];
	while (scanf_s("%d,%d", &a, &b) && a != 0 && b != 0) {
		c.insert(b);
		d[a] = b;
	}
	int i = c.size();
	while (cin >> a){
		b = d[a];
		set<int>::iterator it = c.end();
		it--;
		int sum = 0;
		for (int j = 0; j < i; j++) {
			sum++;
			if ((*it) == b) {
				cout << sum << endl;
				break;
			}
			it--;
		}
	}
}