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

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

void main() {
  Team[] team;
  int[] ranking;
  int i = 0;
  while(true) {
    int[] line = readln.chomp.split(",").map!(to!(int)).array;
    if (line[0] == 0 && line[1] == 0) break;
    team ~= Team(line[0], 0, line[1]);
  }
  sort!((a, b) => a.ans > b.ans)(team);
  auto prev = team[0].ans;
  int rank = 1;
  team[0].ranking = rank;
  foreach(ref t; team[1..$]) {
    if (prev > t.ans) rank++;
    t.ranking = rank;
    prev = t.ans;
  }
  sort!((a, b) => a.id < b.id)(team);
  writeln(team);
  while(true) {
    string number = readln.chomp;
    if (stdin.eof()) break;
    writeln(team[number.to!(int) - 1].ranking);
  }
}