#include <bits/stdc++.h>
using namespace std;
int b[100005], a[100005], k[100005];
string s[100005];
map<string, int> sMap;
bool cmp(int i, int j) {
  return (a[i] < a[j] || (a[i] == a[j] && s[i] > s[j]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(b, 0, sizeof(b));
  memset(a, 0, sizeof(a));
  memset(k, 0, sizeof(k));
  int n = 0, m = 0;
  string name;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> name >> a[i];
    s[i] = name;
    sMap[name] = i + 1;
    k[i] = i;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  cin >> name;
  sort(b, b + m);
  reverse(b, b + m);
  sort(k, k + n, cmp);
  int idx = sMap[name] - 1;
  int sc = b[0] + a[idx];
  int r = 1, p = 1, lv = 0, rv = 0;
  for (int i = 0; i < n; ++i) {
    if (k[i] == idx) {
      continue;
    }
    int tmp = 0;
    if (s[k[i]] < s[idx]) {
      tmp = sc - a[k[i]] - 1;
    } else {
      tmp = sc - a[k[i]];
    }
    if (p >= n || b[p] > tmp) {
      ++r;
    }
    ++p;
  }
  lv = r;
  sc = a[idx] + b[n - 1];
  p = 0;
  r = 1;
  for (int i = 0; i < n; ++i) {
    if (k[i] == idx) {
      continue;
    }
    int tmp = 0;
    if (s[k[i]] < s[idx]) {
      tmp = sc - a[k[i]];
    } else {
      tmp = sc - a[k[i]] + 1;
    }
    if (p < n && b[p] >= tmp) {
      ++p;
      ++r;
    }
  }
  rv = r;
  printf("%d %d", lv, rv);
  return 0;
}
