#include <bits/stdc++.h>
using namespace std;
struct racer {
  string name;
  int s;
  bool operator<(const racer& rhs) const {
    if (s != rhs.s)
      return s > rhs.s;
    else
      return name < rhs.name;
  }
};
racer r[100000], tmp[100000];
int b[100000], u[100000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> r[i].name >> r[i].s;
  sort(r, r + n);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(b, b + m, greater<int>());
  string Vasya;
  cin >> Vasya;
  for (int i = 0; i < n; i++) tmp[i] = r[i];
  for (int i = 0; i < n; i++)
    if (tmp[i].name == Vasya) {
      tmp[i].s += b[0];
      for (int j = n - 1, k = 1; j >= 0 && k < m; j--)
        if (j != i) tmp[j].s += b[k++];
      sort(tmp, tmp + n);
      for (int k = 0; k < n; k++)
        if (tmp[k].name == Vasya) {
          cout << k + 1 << " ";
          break;
        }
      break;
    }
  for (int i = 0; i < n; i++) tmp[i] = r[i];
  for (int i = 0; i < n; i++)
    if (tmp[i].name == Vasya) {
      int res = n;
      tmp[i].s += (m == n ? b[m - 1] : 0);
      for (int j = i + 1; j < n; j++) {
        bool ex = false;
        for (int l = (m == n ? m - 2 : m - 1); l >= 0; l--)
          if (!u[l] &&
              (((b[l] + tmp[j].s) > tmp[i].s) ||
               ((b[l] + tmp[j].s) == tmp[i].s && tmp[j].name < tmp[i].name))) {
            u[l] = 1;
            ex = true;
            break;
          }
        if (!ex) {
          res = j;
          break;
        }
      }
      cout << res << endl;
      break;
    }
  return 0;
}
