#include <bits/stdc++.h>
using namespace std;
struct Y {
  string s;
  int p;
};
const int size = 100000;
Y A[size];
int B[size], n, m, pos;
string name;
bool u[size];
int f() {
  for (int i = 0; i < n; i++)
    if ((A[i].s) == (name)) return i;
}
bool fsort(Y a, Y b) {
  if (a.p != b.p) return a.p > b.p;
  return a.s < b.s;
}
int b_search(int l, int r, int p) {
  int mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (A[mid].p > p)
      l = mid + 1;
    else if (A[mid].p == p && name > A[mid].s)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  int l, r, k, maxp, minp, curp;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> A[i].s >> A[i].p;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> B[i];
  cin >> name;
  sort(A, A + n, fsort);
  sort(B, B + n);
  pos = f();
  maxp = A[pos].p + B[n - 1];
  k = b_search(0, pos, maxp);
  for (int i = k, ai = 0; i < n; i++, ai++)
    if (A[i].s != name) {
      curp = A[i].p + B[ai];
      if (curp >= maxp) {
        if (curp > maxp)
          k++;
        else if (A[i].s < name)
          k++;
      }
    }
  cout << k + 1 << " ";
  minp = A[pos].p + B[0];
  u[0] = true;
  k = 0;
  for (int i = 0; i < n; i++)
    if (A[i].s != name) {
      if (A[i].p > minp) {
        k++;
      } else if (A[i].p == minp && A[i].s < name) {
        k++;
      } else {
        int idx = 0;
        int l = 0, r = n - 1, v = minp - A[i].p;
        while (l <= r) {
          int mid = (l + r) / 2;
          if (B[mid] > v)
            r = mid - 1;
          else
            l = mid + 1;
        }
        idx = l - 3;
        if (idx < 0) idx = 0;
        while (idx < n) {
          if (!u[idx] && A[i].p + B[idx] > minp ||
              (A[i].p + B[idx] == minp && A[i].s < name)) {
            u[idx] = true;
            k++;
            break;
          }
          idx++;
        }
      }
    }
  cout << k + 1 << endl;
  return 0;
}
