#include <bits/stdc++.h>
using namespace std;
int v[100005];
struct node {
  string name;
  int p;
  bool operator<(const node& n) const {
    if (p == n.p) return name > n.name;
    return p < n.p;
  }
} a[100005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].name >> a[i].p;
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> v[i];
  }
  sort(v + 1, v + 1 + m);
  string x;
  cin >> x;
  int index = 1;
  for (int i = 1; i <= n; i++) {
    if (x == a[i].name) {
      index = i;
      break;
    }
  }
  a[index].p += v[m];
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (x == a[i].name) {
      index = i;
      break;
    }
  }
  int ans1 = 0, ans2 = 0;
  int res = m - 1;
  res -= n - index;
  ans1 += n - index;
  for (int i = 1;; i++) {
    if (res <= 0) break;
    int t = a[i].p + v[res];
    if (t > a[index].p || t == a[index].p && a[i].name < a[index].name) {
      ans1++;
      i--;
      res--;
    } else
      res--;
  }
  a[index].p -= v[m];
  res = m;
  int flag = 0;
  if (res == n) {
    a[index].p += v[1];
    flag = 1;
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    if (x == a[i].name) {
      index = i;
      break;
    }
  }
  res = m;
  ans2 += n - index;
  for (int i = 1; i < index; i++) {
    int t = a[i].p + v[res];
    if (t > a[index].p || t == a[index].p && a[i].name < a[index].name) {
      ans2++;
      res--;
    }
    if (res == flag) break;
  }
  cout << ans1 + 1 << ' ' << ans2 + 1 << '\n';
  return 0;
}
