#include <bits/stdc++.h>
using namespace std;
int N;
int M;
long long B[1000010];
int K;
long long A[1000010];
char buf[256];
int main() {
  while (1 == scanf("%d", &N)) {
    map<string, long long> points;
    map<string, int> id;
    for (int i = 0; i < (int)(N); i++) {
      int ptr;
      scanf("%s%d", buf, &ptr);
      points[string(buf)] = ptr;
      id[string(buf)] = 0;
    }
    memset(B, 0, sizeof(B));
    scanf("%d", &M);
    for (int i = 0; i < (int)(M); i++) {
      int b;
      scanf("%d", &b);
      B[i] = b * (long long)N;
    }
    string myname;
    cin >> myname;
    long long P;
    int t = 0;
    K = 0;
    for (__typeof((id).begin()) ite = (id).begin(); ite != (id).end(); ++ite) {
      long long p = points[ite->first];
      p = p * (long long)N + (N - ++t);
      if (ite->first == myname) {
        P = p;
      } else {
        A[K] = p;
        ite->second = K++;
      }
    }
    sort(A, A + K);
    sort(B, B + N);
    {
      long long myp = P + B[N - 1];
      multiset<long long> bs;
      for (int i = 0; i < N - 1; ++i) bs.insert(B[i]);
      int win = 0;
      for (int i = 0; i < (int)(K); i++) {
        __typeof((bs).begin()) ite = bs.lower_bound(myp - A[i]);
        if (ite == bs.begin()) continue;
        --ite;
        ++win;
        bs.erase(ite);
      }
      printf("%d ", N - win);
    }
    {
      long long myp = P + B[0];
      multiset<long long> bs;
      for (int i = 1; i < N; ++i) bs.insert(B[i]);
      int lose = 0;
      reverse(A, A + K);
      for (int i = 0; i < (int)(K); i++) {
        __typeof((bs).begin()) ite = bs.lower_bound(myp - A[i]);
        if (ite == bs.end()) continue;
        ++lose;
        bs.erase(ite);
      }
      printf("%d\n", lose + 1);
    }
  }
  return 0;
}
