#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
int n, H, L, m, sco[100010];
pair<int, string> p[100010], pbuf[100010];
string name;
bool solve();
bool cmp(const pair<int, string>& p1, const pair<int, string>& p2);
bool cmp1(const pair<int, string>& p1, const pair<int, string>& p2);
void compute();
int main() {
  while (solve())
    ;
  return 0;
}
bool solve() {
  if (scanf("%d", &n) == EOF) return false;
  char buf[32];
  for (int i = 0; i < n; ++i) {
    int s;
    scanf("%s%d", buf, &s);
    p[i] = make_pair(s, string(buf));
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) scanf("%d", &sco[i]);
  scanf("%s", buf);
  name = string(buf);
  compute();
  printf("%d %d\n", H, L);
  return true;
}
bool cmp(const pair<int, string>& p1, const pair<int, string>& p2) {
  return p1.first == p2.first ? p1.second < p2.second : p1.first > p2.first;
}
bool cmp1(const pair<int, string>& p1, const pair<int, string>& p2) {
  return p1.first == p2.first ? p1.second > p2.second : p1.first < p2.first;
}
void compute() {
  sort(sco, sco + m, greater<int>());
  copy(p, p + n, pbuf);
  sort(pbuf, pbuf + n, cmp1);
  int cnt = 1;
  for (int i = 0; i < n; ++i) {
    if (pbuf[i].second == name) {
      if (m > 0) pbuf[i].first += sco[0];
    } else {
      if (cnt < m) {
        pbuf[i].first += sco[cnt];
        ++cnt;
      }
    }
  }
  sort(pbuf, pbuf + n, cmp);
  for (int i = 0; i < n; ++i)
    if (pbuf[i].second == name) H = i + 1;
  copy(p, p + n, pbuf);
  if (m == n)
    for (int i = 0; i < n; ++i)
      if (pbuf[i].second == name) pbuf[i].first += sco[m - 1];
  sort(pbuf, pbuf + n, cmp);
  int k = 0;
  while (pbuf[k].second != name) ++k;
  sort(sco, sco + m);
  int p = (m == n ? 1 : 0);
  int cur = pbuf[k].first;
  L = k + 1;
  for (int i = k + 1; i < n; ++i) {
    while (p < m && (pbuf[i].first + sco[p] < cur ||
                     (pbuf[i].first + sco[p] == cur && pbuf[i].second > name)))
      ++p;
    if (p < m) {
      ++L;
      ++p;
    }
  }
}
