#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, m;
int b[N];
struct rec {
  string name;
  int score;
  bool operator<(const rec& rhs) const {
    if (score == rhs.score) {
      return name < rhs.name;
    }
    return score > rhs.score;
  }
};
rec g[N];
int find_name(string name) {
  for (int i = 0; i < n; ++i) {
    if (g[i].name == name) {
      return g[i].score;
    }
  }
  return 0;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> g[i].name >> g[i].score;
  }
  sort(&g[0], &g[n]);
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  sort(&b[0], &b[n]);
  string vname;
  cin >> vname;
  int vscore = find_name(vname);
  int max_score = vscore + b[n - 1];
  int p = 0;
  int max_below = 0;
  for (int i = 0; i < n; ++i) {
    if (g[i].name != vname) {
      if (g[i].score + b[p] < max_score ||
          (g[i].score + b[p] == max_score && g[i].name > vname)) {
        ++max_below;
        ++p;
      }
    }
  }
  p = n - 1;
  int min_before = 0;
  int min_score = vscore + b[0];
  for (int i = n - 1; i >= 0; --i) {
    if (g[i].name != vname) {
      if (g[i].score + b[p] > min_score ||
          (g[i].score + b[p] == min_score && g[i].name < vname)) {
        ++min_before;
        --p;
      }
    }
  }
  cout << n - max_below << ' ' << min_before + 1 << endl;
}
