#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, m;
string s[100000];
int a[100000];
int b[100000];
string name;
int id;
vector<pair<int, string> > All;
bool canMaxi(int k) {
  pair<int, string> He = make_pair(-a[id], name);
  He.first -= b[n - 1];
  for (int i = k - 1; i >= 0; i--) {
    pair<int, string> I = All[i];
    I.first -= b[k - 1 - i];
    if (He < I) return false;
  }
  return true;
}
int findMaxi() {
  int l = n - 1, r = n - 1;
  for (int i = 0; i < (int)((All).size()); i++)
    if (make_pair(-a[id], name) < All[i]) {
      l = i;
      break;
    }
  while (r - l > 1) {
    int k = (l + r) / 2;
    if (canMaxi(k))
      l = k;
    else
      r = k - 1;
  }
  if (l != r && canMaxi(r)) l++;
  return l;
}
bool canMini(int k) {
  pair<int, string> He = make_pair(-a[id], name);
  He.first -= b[0];
  for (int i = k; i < n - 1; i++) {
    pair<int, string> I = All[i];
    I.first -= b[(n - 1) - (i - k)];
    if (!(He < I)) return false;
  }
  return true;
}
int findMini() {
  int l = 0, r = n - 1;
  for (int i = (int)((All).size()) - 1; i >= 0; i--)
    if (make_pair(-a[id], name) < All[i]) {
      r = i;
      break;
    }
  while (r - l > 1) {
    int k = (l + r) / 2;
    if (canMini(k))
      r = k;
    else
      l = k + 1;
  }
  if (l != r && canMini(l)) r--;
  return r;
}
void solution() {
  scanf("%d\n", &n);
  for (int i = 0, _n = (n); i < _n; ++i) {
    char t[64];
    scanf("%s %d\n", t, a + i);
    s[i] = string(t);
  }
  scanf("%d", &m);
  for (int i = 0, _n = (m); i < _n; ++i) scanf("%d\n", b + i);
  sort(b, b + n, greater<int>());
  cin >> name;
  for (int i = 0, _n = (n); i < _n; ++i)
    if (s[i] == name) {
      id = i;
      break;
    }
  for (int i = 0, _n = (n); i < _n; ++i)
    if (i != id) All.push_back(make_pair(-a[i], s[i]));
  sort((All).begin(), (All).end());
  int mini = findMini();
  int maxi = findMaxi();
  printf("%d %d\n", mini + 1, maxi + 1);
}
int main() {
  solution();
  return 0;
}
