#include <bits/stdc++.h>
int b[100005];
int used[100005];
using namespace std;
bool gt(pair<int, string> left, pair<int, string> right) {
  return (left.first > right.first) ||
         (left.first == right.first && left.second < right.second);
}
int main() {
  vector<pair<int, string> > pt;
  int n, m, mypt;
  int rmax, rmin;
  cin >> n;
  string me;
  for (int i = 0; i < n; i++) {
    pair<int, string> p;
    cin >> p.second >> p.first;
    pt.push_back(p);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  cin >> me;
  for (int i = 0; i < n; i++) {
    if (pt[i].second == me) {
      mypt = pt[i].first;
      break;
    }
  }
  sort(pt.begin(), pt.end(), gt);
  sort(b, b + n);
  rmax = 1;
  int j = n - 2;
  for (int i = pt.size() - 1; i >= 0; i--) {
    if (pt[i].second == me) continue;
    for (; j >= 0; j--) {
      if ((mypt + b[n - 1] > pt[i].first + b[j]) ||
          ((mypt + b[n - 1] == pt[i].first + b[j]) && me < pt[i].second)) {
        j--;
        if (j == -1) rmax--;
        break;
      }
    }
    if (j == -1) rmax++;
  }
  rmin = n;
  j = 1;
  for (int i = 0; i < pt.size(); i++) {
    if (pt[i].second == me) continue;
    for (; j < n; j++) {
      if ((mypt + b[0] < pt[i].first + b[j]) ||
          ((mypt + b[0] == pt[i].first + b[j]) && me > pt[i].second)) {
        j++;
        if (j == n) rmin++;
        break;
      }
    }
    if (j == n) rmin--;
  }
  cout << rmax << " " << rmin << endl;
  return 0;
}
