#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int logn = 10;
const int inf = (int)2e9;
const long long mod = (int)1e9 + 7;
const long long base = 2204234849;
const long long l_inf = (long long)4e18;
const long double pi = acos(-1.0);
const long double eps = 1e-12;
int n, m;
pair<int, string> score[maxn];
int add[maxn];
string name;
bool cmp(const pair<int, string> &a, const pair<int, string> &b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  srand(566);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> score[i].second >> score[i].first;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> add[i];
  cin >> name;
  sort(score, score + n, cmp);
  sort(add, add + m);
  int cur = -1;
  for (int i = 0; i < n; i++)
    if (score[i].second == name) cur = i;
  if (m == n) {
    score[cur].first += add[0];
    sort(score, score + n, cmp);
    for (int i = 0; i < n; i++)
      if (score[i].second == name) cur = i;
  }
  int worst = cur + 1;
  for (int i = cur + 1, j = (n == m); i < n && j < m; i++) {
    while (j < m && !cmp(make_pair(score[i].first + add[j], score[i].second),
                         score[cur]))
      j++;
    if (j < m) {
      worst++;
      j++;
    }
  }
  if (m == n) score[cur].first -= add[0];
  if (m != 0) score[cur].first += add[m - 1];
  sort(score, score + n, cmp);
  for (int i = 0; i < n; i++)
    if (score[i].second == name) cur = i;
  m--;
  for (int i = 0; i < cur && m > 0; i++) score[i].first += add[--m];
  for (int i = n - 1, j = m - 1; i > cur; i--) {
    while (j >= 0 && !cmp(score[cur],
                          make_pair(score[i].first + add[j], score[i].second)))
      j--;
    if (j >= 0) {
      score[i].first += add[j--];
      m--;
    }
  }
  for (int i = cur + 1; i < n && m > 0; i++) {
    score[i].first += inf;
    m--;
  }
  sort(score, score + n, cmp);
  int best = -1;
  for (int i = 0; i < n; i++)
    if (score[i].second == name) best = i + 1;
  cout << best << ' ' << worst;
  return 0;
}
