#include <bits/stdc++.h>
using namespace std;
pair<int, string> p[100005];
char me[1005], s[1005];
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 b[100005];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%s%d", s, &x);
    p[i] = make_pair(x, string(s));
  }
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d", &b[i]);
  sort(b, b + m);
  scanf("%s", me);
  for (int i = 0; i < n; i++)
    if (p[i].second == me) {
      swap(p[i], p[n - 1]);
      --n;
      break;
    }
  sort(p, p + n, cmp);
  int v1 = p[n].first + b[m - 1];
  int cnt1 = 0, rc = 0;
  pair<int, string> lme = make_pair(v1, string(me));
  for (int i = n - 1, j = m - 2; i >= 0; i--) {
    while (j >= 0 && cmp(make_pair(p[i].first + b[j], p[i].second), lme)) {
      ++cnt1;
      --j;
    }
    if (j < 0 && i >= cnt1 && cmp(p[i], lme))
      ++rc;
    else if (j >= 0)
      --j;
  }
  ++cnt1;
  int v2 = p[n].first + (m <= n ? 0 : b[0]);
  int cnt2 = 0;
  pair<int, string> rme = make_pair(v2, string(me));
  int tmp = 0, rp = 0;
  for (int i = 0, j = (m > n); i < n; i++) {
    if (cmp(p[i], rme)) {
      tmp++;
      continue;
    }
    while (j < m && cmp(rme, make_pair(p[i].first + b[j], p[i].second))) {
      if (tmp > 0)
        --tmp;
      else
        ++cnt2;
      ++j;
    }
    if (j >= m && i < n - cnt2 && cmp(rme, p[i]))
      ++rp;
    else if (j < m)
      ++j;
  }
  printf("%d %d\n", cnt1 + rc, n - cnt2 - rp + 1);
  return 0;
}
