#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
inline T Sqr(const T &x) {
  return x * x;
}
template <class T>
inline T Abs(const T &x) {
  return x >= 0 ? x : -x;
}
int n, m;
pair<int, string> a[100005];
int b[100005];
char buf[100];
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    scanf("%s", buf);
    int t;
    scanf("%d", &t);
    a[i].first = -t;
    a[i].second = string(buf);
  }
  scanf("%d", &m);
  for (int i = 0; i < (m); i++) scanf("%d", &b[i]);
  sort(a, a + n);
  sort(b, b + n);
  scanf("%s", buf);
  string name(buf);
  int idx = -1;
  for (int i = 0; i < (n); i++)
    if (a[i].second == name) {
      idx = i;
      break;
    }
  if (idx == -1) throw 42;
  int cur = 0;
  int score = a[idx].first - b[n - 1];
  for (int i = 0; i < n; i++)
    if (i != idx) {
      if (make_pair(score, name) <
          make_pair(a[i].first - b[cur], a[i].second)) {
        cur++;
      }
    }
  int bestplace = n - cur;
  score = a[idx].first - b[0];
  cur = n - 1;
  for (int i = n - 1; i >= 0; i--)
    if (i != idx) {
      if (make_pair(a[i].first - b[cur], a[i].second) <
          make_pair(score, name)) {
        cur--;
      }
    }
  int worstplace = n - cur;
  cout << bestplace << " " << worstplace;
}
int main() {
  solve();
  return 0;
}
