#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <cfloat>
using namespace std;
int main(){
	
	int a[100][1];
	int x,y;
	char comma;
	
	while(cin>>x>>comma>>y,x!=0||y!=0){
		a[x][0]=y;
	}
	int f;
	while(cin>>f){
		if(a[f][0]==10)
			cout<<3<<endl;
		else if(a[f][0]==20)
			cout<<2<<endl;
		else
			cout<<1<<endl;
	}
	
	
 	
}