#include <bits/stdc++.h>
using namespace std;
long long ans[300][300][30];
long long cost[30][30];
string spam;
long long m;
vector<pair<long long, string>> a, nn, mm;
vector<long long> pt;
int main() {
  long long n;
  cin >> n;
  getline(cin, spam);
  for (long long i = 0; i < n; ++i) {
    getline(cin, spam);
    long long l = 0;
    string u = "";
    while (spam[l] != ' ') {
      u += spam[l];
      ++l;
    }
    long long ct = 0;
    ++l;
    while (l < spam.length() && spam[l] >= '0' && spam[l] <= '9') {
      ct = ct * 10 + spam[l] - '0';
      ++l;
    }
    a.push_back(make_pair(-ct, u));
  }
  cin >> m;
  long long l;
  for (long long i = 0; i < m; ++i) {
    cin >> l;
    pt.push_back(l);
  }
  sort(pt.begin(), pt.end());
  getline(cin, spam);
  getline(cin, spam);
  l = 0;
  sort(a.begin(), a.end());
  while (a[l].second != spam) ++l;
  for (long long i = 0; i < n; ++i) {
    mm.push_back(a[i]);
    nn.push_back(a[i]);
  }
  if (m == 0) {
    cout << l + 1 << ' ' << l + 1;
    return 0;
  }
  mm[l].first -= pt[m - 1];
  sort(mm.begin(), mm.end());
  long long ll = 0;
  long long rr = m - 2;
  while (mm[ll].second != spam && rr >= 0) {
    mm[ll].first -= pt[rr];
    ++ll;
    --rr;
  }
  ll = n - 1;
  while (rr >= 0) {
    mm[ll].first -= pt[rr];
    --ll;
    --rr;
  }
  sort(mm.begin(), mm.end());
  ll = l + 1;
  rr = 0;
  int p2 = l;
  if (m == n) {
    nn[l].first -= pt[0];
    rr = 1;
  }
  while (ll < n && rr < m) {
    while (rr < m && (nn[ll].first - pt[rr] > nn[l].first ||
                      (nn[ll].first - pt[rr] == nn[l].first &&
                       nn[ll].second > nn[l].second))) {
      ++rr;
    }
    if (rr < m) {
      nn[ll].first -= pt[rr];
      ++p2;
      ++ll;
      ++rr;
    }
  }
  sort(nn.begin(), nn.end());
  long long p1 = 0;
  for (long long i = 0; i < n; ++i) {
    if (mm[i].second == spam) p1 = i;
  }
  cout << p1 + 1 << ' ' << p2 + 1;
  return 0;
}
