#include <bits/stdc++.h>
using namespace std;
struct player {
  string name;
  long long point;
  player() {}
  player(string n, long long p) { name = n, point = p; }
  bool operator<(const player &p) const {
    if (point == p.point) {
      return name < p.name;
    }
    return point > p.point;
  }
};
vector<player> vec, tmp;
vector<long long> prize;
long long n, m, x;
string str;
int index_of() {
  for (int i = 0; i < vec.size(); i++) {
    if (tmp[i].name == str) return i;
  }
}
int find_first_pos(int in) {
  int j = 0;
  for (int i = in; i < tmp.size() && j < prize.size(); i++, j++) {
    tmp[i].point += prize[j];
  }
  for (int i = in - 1; i >= 0 && j < prize.size(); i--, j++) {
    tmp[i].point += prize[j];
  }
  sort(tmp.begin(), tmp.end());
  return index_of() + 1;
}
int find_last_pos(int in) {
  tmp = vec;
  if (prize.size() >= tmp.size()) {
    tmp[in].point += prize[tmp.size() - 1];
  }
  int j = 0;
  for (int i = tmp.size() - 1; i >= 0 && j < prize.size(); i--) {
    if (i != in) {
      player p(tmp[i].name, tmp[i].point + prize[j]);
      if (p < tmp[in]) {
        tmp[i].point += prize[j];
        j++;
      }
    }
  }
  sort(tmp.begin(), tmp.end());
  return index_of() + 1;
}
bool func(int x, int y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(false);
  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> str >> x;
      vec.push_back(player(str, x));
    }
    sort(vec.begin(), vec.end());
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> x;
      prize.push_back(x);
    }
    sort(prize.begin(), prize.end(), func);
    cin >> str;
    tmp = vec;
    long long in = index_of();
    long long fir, sec;
    fir = find_first_pos(in);
    sec = find_last_pos(in);
    cout << fir << " " << sec << endl;
  }
  return 0;
}
