import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;
import std.typecons;

alias Tuple!(int, "id", int, "ans", int, "rank") Team;



void main() {
    Team[] team;
    Team[] ranking;
    int i = 0;

    while (true) {
        int[] input = readln.chomp.split(",").map!(to!int).array;
        if (input == [0,0]) break;

        team ~= Team(input[0], input[1], 0);
    }

    sort!((a, b) => a.ans > b.ans)(team);
    auto prev = team[0].ans;
    auto rankOfNow = 1;
    foreach(ref t; team[0..$]) {
        if (prev > t.ans) rankOfNow++;
        t.rank = rankOfNow;
        prev = t.ans;
    }

    while (true) {
        string number = readln.chomp;
        if (stdin.eof()) break;
        foreach(t; team) if (number.to!int == t.id) writeln(t.rank);
    }
}