#include <bits/stdc++.h>
using namespace std;
struct team {
  string name;
  int pnt;
  team(const string name, int pnt) {
    this->name = name;
    this->pnt = pnt;
  }
};
bool cmp(const team &a, const team &b) {
  if (a.pnt == b.pnt) {
    return a.name < b.name;
  } else {
    return a.pnt > b.pnt;
  }
}
vector<team> v;
int pnt[1000005];
char myTeam[25];
int main() {
  int n;
  scanf("%d", &n);
  int i, j;
  for (i = 0; i < n; i++) {
    char ln[50];
    int x;
    scanf("%s %d", ln, &x);
    v.push_back(team(ln, x));
  }
  int m;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d", &pnt[i]);
  }
  sort(v.begin(), v.end(), cmp);
  sort(pnt, pnt + m);
  scanf("%s", myTeam);
  string str(myTeam);
  int myInitialPos;
  vector<team> tmp;
  for (i = 0; i < n; i++) {
    if (v[i].name == str) {
      myInitialPos = i;
      break;
    }
  }
  for (i = 0; i < n; i++) {
    tmp.push_back(v[i]);
  }
  tmp[myInitialPos].pnt += pnt[m - 1];
  for (i = n - 1, j = m - 2; i >= 0 && j >= 0; i--) {
    if (i == myInitialPos) {
      continue;
    }
    tmp[i].pnt += pnt[j--];
  }
  sort(tmp.begin(), tmp.end(), cmp);
  int hrank;
  for (i = 0; i < n; i++) {
    if (tmp[i].name == str) {
      hrank = i + 1;
      break;
    }
  }
  printf("%d ", hrank);
  tmp.clear();
  for (i = 0; i < n; i++) {
    tmp.push_back(v[i]);
  }
  multiset<int> st;
  for (i = 0; i < m; i++) {
    st.insert(pnt[i]);
  }
  if (m == n) {
    st.erase(st.find(pnt[0]));
    tmp[myInitialPos].pnt += pnt[0];
  }
  sort(tmp.begin(), tmp.end(), cmp);
  int present;
  for (i = 0; i < n; i++) {
    if (tmp[i].name == str) {
      present = i;
      break;
    }
  }
  int s = i;
  for (i = s + 1; i < n; i++) {
    int needMore = (tmp[present].name < tmp[i].name);
    auto x = st.lower_bound((tmp[present].pnt - tmp[i].pnt) + needMore);
    if (x == st.end()) {
      break;
    } else {
      st.erase(x);
    }
  }
  printf("%d\n", i);
  return 0;
}
