#include <bits/stdc++.h>
using namespace std;
int n, i, m, x, j, res;
string str;
pair<string, int> A[100001];
int P[100001], M[100001];
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    cin >> A[i].first;
    scanf("%d", &A[i].second);
  }
  sort(A, A + n);
  scanf("%d", &m);
  for (i = 0; i < m; i++) scanf("%d", &P[i]);
  sort(P, P + n);
  reverse(P, P + n);
  cin >> str;
  for (m = 0; A[m].first != str; m++)
    ;
  for (i = 0; i < n; i++)
    if (i != m) M[j++] = A[i].second + (i < m);
  sort(M, M + n - 1);
  x = P[0] + A[m].second;
  for (i = 0, j = 1; i + 1 < n; i++) {
    while (j < n && M[i] + P[j] > x) j++;
    if (j == n) break;
    j++;
  }
  res = n - i;
  reverse(M, M + n - 1);
  reverse(P, P + n);
  x = P[0] + A[m].second;
  for (i = 0, j = 1; i + 1 < n; i++) {
    while (j < n && M[i] + P[j] <= x) j++;
    if (j == n) break;
    j++;
  }
  printf("%d %d", res, i + 1);
  return 0;
}
