#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int a[31];
	int b[101];
	for(int i=0;i<31;i++) a[i] = 0;
	for(int i=0;i<101;i++) b[i] = 0;
	int c = 0;
	int d,f;
	char e;
	while(1){
		cin >> d >> e >> f;
		if(d+f==0) break;
		a[f]++;
		b[d] = f;
		c++;
	}
	f = 0;
	for(int i=30;i>0;i--){
		if(a[i]!=0){
			f++;
			a[i] = f;
		}
	}
	while(cin >> c){ cout << a[b[c]] << endl; }
}