#include <bits/stdc++.h>
using namespace std;
const int c = 100500;
pair<int, int> a[c];
map<string, int> mp;
string s[c];
char tmp[c];
int p[c];
int n, m;
inline bool ls(const pair<int, int> &p1, const pair<int, int> &p2) {
  if (p1.second != p2.second) return p1.second > p2.second;
  return s[p1.first] < s[p2.first];
}
int main() {
  scanf("%d", &n);
  int i, k;
  char h;
  for (i = 1; i <= n; ++i) {
    h = getchar();
    while (h != '\n')
      ;
    scanf("%s", tmp);
    scanf("%d", &k);
    s[i] = string(tmp);
    mp[s[i]] = i;
    a[i] = pair<int, int>(i, k);
  }
  scanf("%d", &m);
  for (i = 1; i <= m; ++i) scanf("%d", &p[i]);
  h = getchar();
  while (h != '\n')
    ;
  scanf("%s", tmp);
  int vn = mp[tmp];
  sort(p + 1, p + n + 1);
  reverse(p + 1, p + n + 1);
  sort(a + 1, a + n + 1, ls);
  int a1 = 1;
  int lf = 2, rg = n;
  int j;
  for (j = 1; j <= n; ++j)
    if (a[j].first == vn) break;
  for (i = 1; i <= n; ++i)
    if (i != j) {
      if (a[i].second + p[rg] < a[j].second + p[1] ||
          a[i].second + p[rg] == a[j].second + p[1] &&
              s[a[i].first] > s[a[j].first]) {
        rg--;
      } else {
        a1++;
        lf++;
      }
    }
  int a2 = n;
  lf = 1, rg = n - 1;
  for (i = n; i >= 1; --i)
    if (i != j) {
      if (a[i].second + p[lf] > a[j].second + p[n] ||
          a[i].second + p[lf] == a[j].second + p[n] &&
              s[a[i].first] < s[a[j].first]) {
        lf++;
      } else {
        a2--;
        rg--;
      }
    }
  printf("%d %d\n", a1, a2);
  return 0;
}
