#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define pf push_front
#define pb push_back
#define FST first
#define SEC second
#define sz(obj) ((int)(obj).size())

const int INF = 999999999;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  vector<pii > vp;
  vi rank;
  int a, b;
  int t;

  while (scanf("%d, %d", &a, &b), a + b){
    vp.pb(pii(a, b));
  }
  rep(i, sz(vp)){
    FOR(j, 1, sz(vp)){
      if (vp[j - 1].SEC < vp[j].SEC){
        swap(vp[j - 1].FST, vp[j].FST);
        swap(vp[j - 1].SEC, vp[j].SEC);
      }
    }
  }
  rank.pb(1);
  for (int i = 1, j = 1; i < sz(vp); i++){
    if (vp[i - 1].SEC == vp[i].SEC) rank.pb(j);
    else rank.pb(++j);
  }
  while (cin >> t){
    rep(i, sz(vp)){
      if (t == vp[i].FST){
        cout << rank[i] << endl;
      }
    }
  }
}