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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"
#define mod 1000000007
#define INF 100000000

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

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  pair<int, int> p[101];
  int P, S, n = 0;

  while (scanf("%d, %d", &P, &S), P || S){
    p[n].first = S;
    p[n].second = P;
    n++;
  }

  sort(p, p + n);
  reverse(p, p + n);
  int rank[n], boder, j = 0;
  rank[0] = boder = p[0].first;
  for (int i = 1; i <= n; i++){
    if (boder != p[i].first){
      j++;
      rank[j] = p[i].first;
    }
  }
  int q;
  
  while (cin >> q){
    for (int i = 0; i < n; i++){
      if (q == p[i].second){
        for (int j = 0; j < n; j++){
          if (p[i].first == rank[j]){
            cout << j + 1 << endl;
            break;
          }
        }
      }
    }
  }
}