#include <bits/stdc++.h>
using namespace std;
struct pl {
  string s;
  int a;
  int f;
};
int n, m;
vector<pl> a, aw, al;
int zw, zl, mw, ml;
int v;
vector<int> b, ba;
string t;
bool tmpb(int p, int q) {
  if (p > q)
    return true;
  else
    return false;
}
bool tmpa(pl p, pl q) {
  if (p.a > q.a || p.a == q.a && p.s < q.s)
    return true;
  else
    return false;
}
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].s >> a[i].a;
    a[i].f = 0;
  }
  cin >> m;
  b.resize(n);
  for (int i = 0; i < m; i++) cin >> b[i];
  for (int i = m; i < n; i++) b[i] = 0;
  cin >> t;
  sort(b.begin(), b.end(), tmpb);
  sort(a.begin(), a.end(), tmpa);
  aw = a;
  for (int i = 0; i < n; i++)
    if (a[i].s == t) {
      aw[i].a += b[0];
      aw[i].f = 1;
    }
  sort(aw.begin(), aw.end(), tmpa);
  for (int i = 0; i < n; i++) {
    if (aw[i].s == t) zw = i + 1;
  }
  mw = zw;
  v = n - 1;
  for (int i = zw; i < n; i++) {
    if (aw[zw - 1].a > aw[i].a + b[v] ||
        aw[zw - 1].a == aw[i].a + b[v] && aw[zw - 1].s < aw[i].s)
      v--;
    else
      mw++;
  }
  al = a;
  for (int i = 0; i < n; i++)
    if (a[i].s == t) {
      al[i].a += b[n - 1];
      al[i].f = 1;
    }
  sort(al.begin(), al.end(), tmpa);
  for (int i = 0; i < n; i++) {
    if (al[i].s == t) zl = i + 1;
  }
  ml = zl;
  v = 0;
  for (int i = n - 1; i >= zl; i--) {
    if (al[zl - 1].a < al[i].a + b[v] ||
        al[zl - 1].a == al[i].a + b[v] && al[zl - 1].s > al[i].s) {
      v++;
      ml++;
    }
  }
  cout << mw << " " << ml;
  return 0;
}
