#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
int n, m;
map<string, int> Map;
string c_name[100500];
string my_name;
long long A[100500];
long long B[100500];
long long C[100500];
void sol() {
  map<string, int>::iterator it;
  int i = 1;
  for (it = Map.begin(); it != Map.end(); it++) it->second = i++;
  for (int a = (1); a <= (n); a++) A[a] += 100500 - Map[c_name[a]];
  long long my_rem = 100500 - Map[my_name];
  sort(A + 1, A + n + 1);
  sort(B + 1, B + n + 1);
  int c_sz = 1;
  for (int a = (1); a <= (n); a++)
    if (A[a] % 1000000 == my_rem) C[c_sz++] = A[a] + B[n];
  int ii = n - 1;
  for (int a = (1); a <= (n); a++)
    if (A[a] % 1000000 != my_rem) {
      C[c_sz++] = A[a] + B[ii];
      ii--;
    }
  sort(C + 1, C + n + 1);
  reverse(C + 1, C + n + 1);
  int ans1 = 0, ans2 = 1;
  for (int a = (1); a <= (n); a++)
    if (C[a] % 1000000 == my_rem) ans1 = a;
  c_sz = 1;
  for (int a = (1); a <= (n); a++)
    if (A[a] % 1000000 == my_rem) C[c_sz++] = A[a] + B[1];
  ii = n;
  for (int a = (1); a <= (n); a++)
    if (A[a] % 1000000 != my_rem)
      if (A[a] + B[ii] > C[1]) {
        ans2++;
        ii--;
      }
  cout << ans1 << " " << ans2;
}
int main() {
  scanf("%d", &n);
  char S[100];
  int x;
  for (int a = (1); a <= (n); a++) {
    scanf("%s%d", S, &x);
    c_name[a] = string(S);
    Map[string(S)] = 0;
    A[a] = (long long)x * (long long)1000000;
  }
  scanf("%d", &m);
  for (int a = (1); a <= (m); a++) {
    scanf("%d", &x);
    B[a] = (long long)x * (long long)1000000;
  }
  scanf("%s", S);
  my_name = string(S);
  sol();
  return 0;
}
