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

using namespace std;


int main()
{
    set<int, greater<int> > p;
    map<int, int > r;
    int n, m;
    char comma;
    while(cin >> n >> comma >> m && n && m)
    {
        r.insert(map<int, int >::value_type(n, m));
        p.insert(m);
    }
    while(cin >> n)
    {
        set<int, greater<int> >::iterator it = p.begin();
        int count = 1;
        while(it!=p.end())
        {
            if(*it==r[n])
            {
                cout << count << endl;
                break;
            }
            else
            {
                ++count;
                ++it;
            }
        }
    }
}