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

using namespace std;

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