#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
struct date{
    int team,point,rank;
};
int main(){
    int n,m;
    date a[101];
    int k=1;
    while(scanf("%d,%d",&n,&m),n,m){
        a[k].team = n,a[k].point=m;
        k++;
    }
    k--;
    int t[101] = {0};
    int l = 0;
    for(;scanf("%d",&t[l])!=EOF;l++);
    for(int i = 1; i <= k; i++){
        for(int j = i; j <= k; j++){
            if(a[i].point < a[j].point)swap(a[i],a[j]);
        }
    }

    a[1].rank = 1;
    for(int i = 2; i <= k; i++){
        if(a[i].point == a[i-1].point){
            a[i].rank = a[i-1].rank;
        }
        else a[i].rank = a[i-1].rank + 1;
    }
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            if(a[i].team < a[j].team)swap(a[i],a[j]);
        }
    }
    for(int i = 0; i < l; i++){
        cout << a[t[i]].rank << endl;
    }
    return 0;
}