import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    int[101] team;
    int count = 0;
    while(true){
	auto s = split(chomp(readln()),',');
	int n1 = to!int(s[0])-1;
	int n2 = to!int(s[1]);
	if(n1==-1&&n2==0) break;
	team[n1] = n2;
	count++;
    }
    int[101] rank;
    int r = 1;
    bool flg = false;
    for(int i=30;i>=0;i--){
	flg = false;
	for(int j=0;j<count;j++){
	    if(team[j] == i){
	       	rank[j] = r;
		flg = true;
	    }
	}
	if(flg) r++;
    }
    
    while(true){
	auto s1 = readln();
	if(stdin.eof()) break;
	int n = to!int(chomp(s1));
	writeln(rank[n-1]);
    }
}