#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

map<int, int> grade;
set<int, greater<int> > rank;
int qrank[31];
int main()
{
    int team, score;
    int count=1;
    char comma;
    while(cin >> team >> comma >> score && team && score)
    {
        grade.insert(map<int, int>::value_type(team, score));
        rank.insert(score);
    }
    set<int, greater<int> >::iterator it = rank.begin();
    while(cin >> team)
    {
        it = rank.begin();
        count = 1;
        while(it != rank.end())
        {
            if(grade[team] == *it) cout << count << endl;
            ++count;
            ++it;
        }
    }
    //while(cin >> team) cout << qrank[grade[team]] << endl;
}