#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(void){
    int n,m,k=0,l,z=0;
    int c=1;
    int data[101]={0};
    int rank[31]={0};
    int flag[31]={0};
    while(scanf("%d,%d",&n,&m),n&&m){
        data[n]+=m;
        k=max(k,data[n]);
        z=max(z,n);
    }
    for(int i=0;i<=z;i++){
        flag[data[i]]=1;
    }
    for(int i=k;i>=0;i--){
        if(flag[i]==1){
            rank[i]+=c;
            c++;
        }
    }
    
    while(cin>>l){
        cout<<rank[data[l]]<<endl;
    }
    return(0);
}