#include <bits/stdc++.h>
using namespace std;
int A[1 << 17];
char buf[32];
int F(vector<pair<int, string> >& v, pair<int, string> t) {
  int n = int((v).size());
  t.first -= A[0];
  int Min = 0, Max = n + 1;
  while (Max - Min > 1) {
    int Mid = (Max + Min) >> 1;
    int i;
    int pos = n;
    for (i = (n - Mid); i < (n); ++i) {
      pair<int, string> tt = v[i];
      tt.first -= A[pos];
      --pos;
      if (tt < t) break;
    }
    if (i == n)
      Min = Mid;
    else
      Max = Mid;
  }
  return n - Min;
}
int G(vector<pair<int, string> >& v, pair<int, string> t) {
  int n = int((v).size());
  t.first -= A[n];
  int Min = 0, Max = n + 1;
  while (Max - Min > 1) {
    int Mid = (Max + Min) >> 1;
    int i;
    int pos = Mid;
    for (i = (0); i < (Mid); ++i) {
      --pos;
      pair<int, string> tt = v[i];
      tt.first -= A[pos];
      if (t < tt) break;
    }
    if (i == Mid)
      Min = Mid;
    else
      Max = Mid;
  }
  return Min;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, string> > v;
  int i;
  for (i = (0); i < (n); ++i) {
    int a;
    scanf("%s%d", buf, &a);
    v.push_back(make_pair(-a, buf));
  }
  int m;
  scanf("%d", &m);
  memset(A, 0, sizeof(A));
  for (i = (0); i < (m); ++i) scanf("%d", &A[i]);
  sort(A, A + n);
  reverse(A, A + n);
  scanf("%s", buf);
  for (i = (0); i < (n); ++i)
    if (v[i].second == buf) break;
  pair<int, string> t = v[i];
  v.erase(v.begin() + i);
  sort((v).begin(), (v).end());
  printf("%d %d\n", F(v, t) + 1, G(v, t) + 1);
  return 0;
};
