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

int main () {
    map<int, int> teams;
    set<int, greater<int> > ranks;
    int id, solve;
    while (scanf("%d,%d", &id, &solve), id && solve) {
        teams[id] = solve;
        ranks.insert(solve);
    }

    while (cin >> id) {
        int rank = 1;
        for (set<int, greater<int> >::iterator it = ranks.begin(); it != ranks.end(); it++, rank++) {
            if (*it == teams[id]) {
                cout << rank << endl;
                break;
            }
        }
    }
}