#include <bits/stdc++.h>
using namespace std;
string vasya;
pair<string, int> result[100001];
int points[100001], n;
bool comp(const pair<string, int>& a, const pair<string, int>& b) {
  if (a.second == b.second) return a.first > b.first;
  return a.second < b.second;
}
int findvasya() {
  for (int i = 0; i < n; i++) {
    if (result[i].first == vasya) return i;
  }
}
int main() {
  int i, j, m, vasya_pos, vasya_result, cnt, start;
  cin >> n;
  for (i = 0; i < n; i++) cin >> result[i].first >> result[i].second;
  sort(result, result + n, comp);
  cin >> m;
  for (i = 0; i < m; i++) cin >> points[i];
  for (i = m; i < n; i++) points[i] = 0;
  sort(points, points + n);
  cin >> vasya;
  vasya_pos = findvasya();
  vasya_result = result[vasya_pos].second + points[n - 1];
  cnt = vasya_pos;
  start = 0;
  for (i = n - 1; i > vasya_pos; i--) {
    if (result[i].second + points[start] < vasya_result) {
      cnt++;
      start++;
    }
  }
  cout << n - cnt << " ";
  vasya_pos = findvasya();
  vasya_result = result[vasya_pos].second + points[0];
  cnt = 0;
  start = n - 1;
  for (i = 0; i < vasya_pos; i++) {
    if (points[start] + result[i].second > vasya_result) {
      start--;
      cnt++;
    }
  }
  cout << n - vasya_pos + cnt;
  return 0;
}
