#include <bits/stdc++.h>
using namespace std;
using namespace std;
bool comp(pair<int, string> x, pair<int, string> y) {
  return (x.first > y.first || (x.first == y.first && x.second < y.second));
}
const int N = 100005;
string t;
int me, best, worst, m, i, n, c[N];
pair<int, string> a[N], q[N];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i].second >> a[i].first;
  cin >> m;
  for (i = 0; i < m; i++) cin >> c[i];
  sort(c, c + m);
  cin >> t;
  for (i = 0; i < n; i++)
    if (a[i].second == t) me = i;
  pair<int, string> x = a[me];
  for (i = 0; i < n; i++)
    if (i < me)
      a[i] = a[i];
    else if (i > me)
      a[i - 1] = a[i];
    else
      continue;
  n--;
  int cnt = m - 2;
  sort(a, a + n, comp);
  for (i = 0; i < n; i++) q[i] = a[i];
  for (i = n - 1; i >= 0; i--) {
    if (cnt < 0) break;
    q[i].first += c[cnt];
    cnt--;
  }
  best = 1;
  for (i = 0; i < n; i++)
    if (x.first + c[m - 1] < q[i].first ||
        (x.first + c[m - 1] == q[i].first && x.second > q[i].second))
      best++;
  for (i = 0; i < n; i++) q[i] = a[i];
  if (n + 1 == m) {
    x.first += c[0];
    cnt = 1;
  } else
    cnt = 0;
  i = 0;
  while (cnt < m) {
    if (i == n) break;
    if (q[i].first > x.first ||
        (q[i].first == x.first && q[i].second < x.second))
      i++;
    else if (q[i].first + c[cnt] > x.first ||
             (q[i].first + c[cnt] == x.first && q[i].second < x.second)) {
      q[i].first += c[cnt];
      i++;
      cnt++;
    } else
      cnt++;
  }
  worst = 1;
  for (i = 0; i < n; i++)
    if (x.first < q[i].first ||
        (x.first == q[i].first && x.second > q[i].second))
      worst++;
  cout << best << " " << worst;
}
