#include<iostream>
#include<vector>
#include<stdio.h>
using namespace std;

int get_where_organ(vector<int> v, int organ) {
	for (int i = 0; i < v.size(); i++) {
		if (v[i] == organ)return i;
	}
}
int main() {
	vector<int> group, correct,priorities,organ_nums; int g, c,organ_num;
	while(true){//??´???????????¨??£?§£??°????????????????????£??\
		scanf("%d,%d", &g, &c);
		if (g == 0 && c == 0)break;
		group.push_back(g); correct.push_back(c);
	}
	for (int i = 0;i<correct.size()-1 ; i++) {//group??¨correct???????????????????????????????????????????????????
		for (int j = correct.size() - 1; i < j; j--) {
			if (correct[j] > correct[j - 1]) {
				int num_org = correct[j]; int num_gro = group[j];
				correct[j] = correct[j - 1]; group[j] = group[j - 1];
				correct[j - 1] = num_org; group[j - 1] = num_gro;
			}
		}
	}
	 //??£?§£??°?????????????????????????????????
	int priority = 1; priorities.push_back(priority);
	for (int i = 1; i < group.size(); i++) {
		if (correct[i] == correct[i - 1]){priorities.push_back(priority);
	}
		else {
			priority++; priorities.push_back(priority);
		}
	}
	while(cin>>organ_num){//??????????¬?????????´???????????????????????????
		organ_nums.push_back(organ_num);
	}
	for (int i = 0; i < organ_nums.size(); i++) {
		cout << priorities[get_where_organ(group,organ_nums[i])] << endl;
	}
	return 0;
}