#include <bits/stdc++.h>
using namespace std;
int p[100010];
struct bb {
  string s;
  int t;
} a[100010];
bool cmp(const bb x, const bb y) {
  return x.t > y.t || (x.t == y.t && x.s < y.s);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i].s >> a[i].t;
  int m;
  cin >> m;
  memset(p, 0, sizeof(p));
  for (int i = 0; i < m; i++) cin >> p[i];
  sort(p, p + n);
  bb me;
  cin >> me.s;
  for (int i = 0, j = 0; i < n; i++)
    if (a[i].s == me.s)
      me.t = a[i].t;
    else {
      a[j].s = a[i].s;
      a[j++].t = a[i].t;
    }
  me.t += p[n - 1];
  sort(a, a + n - 1, cmp);
  int r = n - 2;
  int ans1 = n, ans2 = 1;
  for (int i = n - 2; i >= 0; i--) {
    for (; r >= 0; r--)
      if (a[i].t + p[r] < me.t || (a[i].t + p[r] == me.t && a[i].s > me.s))
        break;
    if (r >= 0) {
      ans1--;
      r--;
    } else
      break;
  }
  me.t -= p[n - 1];
  me.t += p[0];
  int j = 1;
  for (int i = 0; i < n - 1; i++) {
    for (; j < n; j++)
      if (a[i].t + p[j] > me.t || (a[i].t + p[j] == me.t && a[i].s < me.s))
        break;
    if (j < n) {
      ans2++;
      j++;
    } else
      break;
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}
