import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int[int] team, rank;
	while (1) {
		auto x = readln.chomp.split(",").map!(to!int);
		if (!x[0] && !x[1]) break;
		team[x[0]] = x[1];
		rank[x[1]] = 1;
	}

	foreach (line; stdin.byLine) {
		auto n = line.chomp.to!int;
		auto score = team[n];
		foreach (i, e; rank.keys.sort!("a>b").array) {
			if (e == score) {
				writeln(i+1);
				break;
			}
		}
	}
}