#include <bits/stdc++.h>
using namespace std;
struct Racer {
  string name;
  int score;
};
bool my_less(Racer first, Racer second) {
  if (first.score != second.score) {
    return (first.score < second.score);
  } else {
    return first.name > second.name;
  }
}
bool my_more(Racer first, Racer second) { return !my_less(first, second); }
int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int FindMaxPlace(vector<Racer> racers, vector<int> bonuses,
                 bool (*Less)(Racer first, Racer second), string Vasyas_name) {
  int Vasyas_place;
  for (int i = 0; i < racers.size(); i++) {
    if (racers[i].name == Vasyas_name) {
      Vasyas_place = i;
    }
  }
  if (bonuses.size() == 0) {
    return Vasyas_place;
  }
  set<int> free_bonuses_indexes;
  for (int i = 0; i < bonuses.size(); ++i) {
    free_bonuses_indexes.insert(i);
  }
  racers[Vasyas_place].score += bonuses[0];
  free_bonuses_indexes.erase(0);
  vector<bool> was_racer_bonused(racers.size(), false);
  int current_bonus_index = 1;
  for (int racer_index = racers.size() - 1; racer_index >= 0; --racer_index) {
    if (racer_index == Vasyas_place) {
      continue;
    }
    while (current_bonus_index < bonuses.size()) {
      racers[racer_index].score += bonuses[current_bonus_index];
      if (Less(racers[racer_index], racers[Vasyas_place])) {
        free_bonuses_indexes.erase(current_bonus_index);
        was_racer_bonused[racer_index] = true;
        current_bonus_index++;
        break;
      } else {
        racers[racer_index].score -= bonuses[current_bonus_index];
        current_bonus_index++;
      }
    }
  }
  for (int racer_index = racers.size() - 1; !free_bonuses_indexes.empty();
       --racer_index) {
    if (racer_index != Vasyas_place && !was_racer_bonused[racer_index]) {
      racers[racer_index].score += bonuses[*free_bonuses_indexes.begin()];
      free_bonuses_indexes.erase(free_bonuses_indexes.begin());
    }
  }
  int final_Vasyas_place = 0;
  for (int racer_index = 0; racer_index < racers.size(); ++racer_index) {
    if (racer_index != Vasyas_place) {
      if (Less(racers[Vasyas_place], racers[racer_index])) {
        final_Vasyas_place++;
      }
    }
  }
  return final_Vasyas_place + 1;
}
int main() {
  vector<Racer> racers;
  vector<int> bonuses;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    Racer r;
    cin >> r.name >> r.score;
    racers.push_back(r);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int bonus;
    cin >> bonus;
    bonuses.push_back(bonus);
  }
  while (bonuses.size() < racers.size()) {
    bonuses.push_back(0);
  }
  string Vasyas_name;
  cin >> Vasyas_name;
  sort(racers.begin(), racers.end(), my_more);
  sort(bonuses.begin(), bonuses.end(), std::greater<int>());
  cout << FindMaxPlace(racers, bonuses, my_less, Vasyas_name) << ' ';
  sort(racers.begin(), racers.end(), my_less);
  sort(bonuses.begin(), bonuses.end(), std::less<int>());
  cout << racers.size() - FindMaxPlace(racers, bonuses, my_more, Vasyas_name) +
              1
       << endl;
  return 0;
}
