#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
char buf[100000];
vector<pair<int, string> > vp;
int b[maxn], n, m;
pair<int, string> me;
int getL() {
  int tx = 0, ret = 1;
  if (m == n) {
    me.first -= b[0];
    tx = 1;
  }
  for (int i = 0; i < (int)vp.size(); i++) {
    if (vp[i] < me) {
      ret++;
      continue;
    }
    while (tx < m) {
      pair<int, string> tmp = vp[i];
      tmp.first -= b[tx];
      tx++;
      if (tmp < me) {
        ret++;
        break;
      }
    }
  }
  if (m == n) me.first += b[0];
  return ret;
}
int getH() {
  me.first -= b[m - 1];
  int tx = m - 2, ret = 1;
  vector<pair<int, string> > vp2;
  for (int i = 0; i < (int)vp.size(); i++) {
    if (vp[i] < me) {
      if (tx >= 0) tx--;
      ret++;
    } else
      vp2.push_back(vp[i]);
  }
  for (int i = (int)vp2.size() - 1; i >= 0; i--) {
    while (tx >= 0) {
      pair<int, string> tmp = vp2[i];
      tmp.first -= b[tx];
      tx--;
      if (tmp < me) {
        ret++;
      } else
        break;
    }
  }
  while (tx >= 0) {
    ret++;
    tx--;
  }
  me.first += b[m - 1];
  return ret;
}
int main() {
  while (scanf("%d", &n) != EOF) {
    vp.clear();
    for (int i = 0; i < n; i++) {
      int tmp;
      scanf("%s%d", buf, &tmp);
      vp.push_back(make_pair(-tmp, string(buf)));
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
      scanf("%d", &b[i]);
    }
    sort(b, b + m);
    scanf("%s", buf);
    string s(buf);
    for (int i = 0; i < (int)vp.size(); i++) {
      if (vp[i].second == s) {
        me = vp[i];
        swap(vp[i], vp[vp.size() - 1]);
        vp.pop_back();
        break;
      }
    }
    sort(vp.begin(), vp.end());
    printf("%d %d\n", getH(), getL());
  }
  return 0;
}
