#include <bits/stdc++.h>
using namespace std;
map<string, int> racerid;
int n, m, a[100010], x, k[100010];
string s;
struct node {
  string name;
  int point;
} racer[100010], temp[100010], me;
int cmp(const int &a, const int &b) {
  return racer[a].point == racer[b].point ? racer[a].name > racer[b].name
                                          : racer[a].point < racer[b].point;
}
inline int findme() {
  for (int i = 0; i < n; i++)
    if (racer[k[i]].name == s) return i;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s >> x;
    racerid[s] = i;
    racer[i].name = s;
    racer[i].point = x;
    k[i] = i;
  }
  cin >> m;
  for (int i = 0; i < m; i++) cin >> a[i];
  sort(a, a + n);
  reverse(a, a + n);
  m = n;
  cin >> s;
  sort(k, k + n, cmp);
  int me = findme();
  int add = 1, r = 1, mypoint = racer[k[me]].point + a[0];
  for (int i = 0; i < n; i++)
    if (i != me) {
      int delta = mypoint - racer[k[i]].point;
      if (racer[k[i]].name > s) delta++;
      if (add >= m || a[add] >= delta) r++;
      add++;
    }
  cout << r << " ";
  add = 0, r = 1, mypoint = racer[k[me]].point + a[n - 1];
  for (int i = 0; i < n; i++)
    if (i != me) {
      int delta = mypoint - racer[k[i]].point;
      if (racer[k[i]].name > s) delta++;
      if (add < n && a[add] >= delta) {
        add++;
        r++;
      }
    }
  cout << r << endl;
}
