#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int main() {
    int solves[31] = {};
    map<int, int> teams;
    while (true) {
        int team, solved;
        scanf("%d,%d", &team, &solved);
        if ((team | solved) == 0) {
            break;
        }
        teams.insert(make_pair(team, solved));
        solves[solved]++;
    }
    int ranks[31] = {};
    for (int i = 30; i > 0; i--) {
        if (i < 30) {
            ranks[i] = ranks[i + 1];
        }
        ranks[i] += (solves[i]) ? 1 : 0;
    }
    int team;
    while (cin >> team) {
        cout << ranks[teams[team]] << endl;
    }
}