#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
pair<int, string> a[100100];
int b[100100], N;
int main() {
  cin >> N;
  for (int i = (0); i < (N); i++) cin >> a[i].second >> a[i].first;
  for (int i = (0); i < (N); i++) a[i].first = -a[i].first;
  memset(b, 0, sizeof(b));
  int M;
  cin >> M;
  for (int i = (0); i < (M); i++) cin >> b[i];
  sort(b, b + N);
  sort(a, a + N);
  string name;
  cin >> name;
  int id = 0;
  for (int i = (0); i < (N); i++)
    if (a[i].second == name) {
      id = i;
      break;
    }
  int mi = id + 1;
  int u = 1;
  int low = a[id].first - b[0];
  while (mi < N) {
    while (u != N) {
      int sc = a[mi].first - b[u];
      if (sc < low || (sc == low && a[mi].second < name)) break;
      u++;
    }
    if (u == N) break;
    mi++;
    u++;
  }
  int ma = id;
  int hi = a[id].first - b[N - 1];
  u = N - 2;
  while (ma) {
    while (u >= 0) {
      int sc = a[ma - 1].first - b[u];
      if (sc > hi || (sc == hi && a[ma - 1].second > name)) break;
      --u;
    }
    if (u < 0) break;
    ma--;
    --u;
  }
  cout << (ma + 1) << " " << mi << endl;
  return 0;
}
