#include <bits/stdc++.h>
using namespace std;
 
int main() {
    map<int, int> a; // ??´???????????¨??£?§£??°????????????
    map<int ,int> m; // ??£?§£??°??¨??????????????????
    int x, y;
    while(~scanf("%d,%d\n", &x, &y)) {
        if(x == 0 && y == 0) break;
        a[x] = y; m[y];
    }

    int j = 1;
    for(auto &s : m) s.second = j++;

    int n;
    while(cin >> n) cout << j - m[a[n]] << endl;
    return 0;
}