#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename C>
ostream& operator<<(ostream& os, const vector<C>& v) {
  for (__typeof((v).begin()) __it = (v).begin(); __it != (v).end(); __it++)
    os << *(__it) << ' ';
  return os;
}
const int inf = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double pi = acos(-1.0);
const double eps = 1e-5;
struct user {
  string name;
  int points;
  user() {}
  user(string s, int a) : name(s), points(a) {}
};
bool operator<(const user& a, const user& b) {
  if (a.points != b.points) return a.points > b.points;
  return a.name < b.name;
}
const int maxn = 100500;
user us[maxn];
int b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    int bb;
    cin >> bb;
    us[i] = user(a, bb);
  }
  sort(us, us + n);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(b, b + m, greater<int>());
  string iam;
  cin >> iam;
  user vasya;
  int myid;
  for (int i = 0; i < n; i++)
    if (us[i].name == iam) {
      vasya = us[i];
      myid = i;
      for (int j = i + 1; j < n; j++) us[j - 1] = us[j];
      n--;
      break;
    }
  int left = -1;
  int right = n + 1;
  int myp = vasya.points + b[0];
  while (right - left > 1) {
    int mid = (left + right) / 2;
    bool ok = true;
    for (int i = mid, j = n; i < n; i++, j--) {
      int pid = mid + (n - mid) - (i - mid);
      pid = j;
      int p = us[i].points;
      if (pid) p += b[pid];
      if (p > myp || (p == myp && us[i].name < iam)) {
        ok = false;
        break;
      }
    }
    if (ok)
      right = mid;
    else
      left = mid;
  }
  cout << right + 1 << ' ';
  left = -1;
  right = n + 1;
  myp = vasya.points + b[n];
  while (right - left > 1) {
    int mid = (left + right) / 2;
    bool ok = true;
    for (int i = mid - 1, j = 0; i >= 0; i--, j++) {
      if (i > n) {
        j--;
        continue;
      }
      int p = us[i].points + b[j];
      if (p < myp || (p == myp && us[i].name > iam)) {
        ok = false;
        break;
      }
    }
    if (ok)
      left = mid;
    else
      right = mid;
  }
  cout << left + 1 << endl;
  return 0;
}
