module AOJ_Volume0061;

import std.stdio,std.string,std.conv,std.array;

int main()
{
	int v[101];
	int[] rank;
	while(true)
	{
		string[] s = readln.chomp.split(",");
		int a = s[0].to!int;
		int b = s[1].to!int;

		if(a == 0 && b == 0) break;
		v[a] = b;

		if(rank.length == 0)
		{
			rank ~= b;
		}
		else
		{
			bool flag = true;
			foreach(i;0..rank.length)
			{
				if(b == rank[i]) flag = false;
			}

			if(flag) rank ~= b;
		}
	}

	rank.sort.reverse;
	string s;
	while((s = readln.chomp).length != 0)
	{
		int team = s.to!int;
		foreach(i;0..rank.length)
		{
			if(rank[i] == v[team])
			{
				writeln(i+1);
			}
		}
	}
	return 0;
}