#include <bits/stdc++.h>
using namespace std;
struct tom {
  string na;
  int h;
} a[100005], c[100005];
int b[100005];
bool z(tom x, tom y) { return x.h < y.h || (x.h == y.h && x.na > y.na); }
bool w(tom x, tom y) { return x.h > y.h || (x.h == y.h && x.na < y.na); }
int n, m;
string ni;
int g() {
  for (int i = 1; i <= n; i++) c[i] = a[i];
  c[1].h += b[n];
  int p = 1, l = n - 1, q = 1;
  for (int i = n; i > 1; i--) {
    c[i].h += b[p];
    if (w(c[1], c[i]))
      p++;
    else
      q++, l--;
  }
  return q;
}
int l() {
  for (int i = 1; i <= n; i++) c[i] = a[i];
  c[1].h += b[1];
  int p = 2, q = n, l = 1;
  for (int i = 2; i <= n; i++) {
    c[i].h += b[q];
    if (w(c[1], c[i]))
      p++;
    else
      l++, q--;
  }
  return l;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i].na >> a[i].h;
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> b[i];
  cin >> ni;
  int p = -1;
  for (int i = 1; i <= n; i++)
    if (a[i].na == ni) {
      p = i;
      break;
    }
  swap(a[p], a[1]);
  sort(a + 2, a + n + 1, z);
  sort(b + 1, b + n + 1);
  cout << g() << " " << l();
  return 0;
}
