#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

struct Member {
    Member() {}
    Member(const string& s, const int rate, const int order) : name{s}, rating{rate}, order{order} {}
    string name;
    int rating;
    int order;
    bool operator<(const Member& m) const
    {
        return (rating != m.rating) ? rating < m.rating : order < m.order;
    }
    bool operator>(const Member& m) const
    {
        return (rating != m.rating) ? rating > m.rating : order > m.order;
    }
};

int main()
{
    int N;
    cin >> N;
    using P = pair<int, int>;
    map<string, P> name_to_score;
    int num = 0;
    set<Member> upper;
    set<Member, greater<Member>> lower;
    vector<Member> initial(N);
    for (int i = 0; i < N; i++) {
        string s;
        int score;
        cin >> s >> score;
        name_to_score[s] = make_pair(score, num);
        initial[i] = Member{s, score, num};
        num++;
    }
    sort(initial.begin(), initial.end());
    for (int i = 0; i < N - N / 5; i++) {
        lower.insert(initial[i]);
    }
    for (int i = 0; i < N / 5; i++) {
        upper.insert(initial[i + N - N / 5]);
    }
    int M;
    cin >> M;
    int day = num;
    for (int i = 0; i < M; i++) {
        char c;
        string s;
        cin >> c >> s;
        if (c == '+') {
            int n;
            cin >> n;
            const Member comer{s, n, day};
            name_to_score[s] = make_pair(n, day);
            num++;
            if (num < 5) {
                cout << comer.name << " is not working now." << endl;
                lower.insert(comer);
                continue;
            }

            const auto maxi = *lower.begin();
            if (num % 5 != 0) {
                const auto mini = *upper.begin();
                if (mini > comer or num < 5) {
                    cout << comer.name << " is not working now." << endl;
                    lower.insert(comer);
                } else {
                    cout << comer.name << " is working hard now." << endl;
                    upper.erase(upper.begin());
                    lower.insert(mini);

                    upper.insert(comer);
                    cout << mini.name << " is not working now." << endl;
                }
            } else {
                if (maxi < comer) {
                    cout << comer.name << " is working hard now." << endl;
                    upper.insert(comer);
                } else {
                    cout << comer.name << " is not working now." << endl;
                    upper.insert(maxi);
                    lower.erase(lower.begin());

                    lower.insert(comer);
                    cout << maxi.name << " is working hard now." << endl;
                }
            }
        } else {
            const auto score = name_to_score[s];
            name_to_score.erase(s);
            auto it = lower.find(Member{s, score.first, score.second});
            bool from_lower = true;
            if (it == lower.end()) {
                from_lower = false;
                it = upper.find(Member{s, score.first, score.second});
            }
            const Member outer = *it;
            if (from_lower) {
                lower.erase(it);
            } else {
                upper.erase(it);
            }
            num--;
            if (num % 5 != 4) {
                if (not from_lower) {
                    const Member add = *lower.begin();
                    lower.erase(add);
                    upper.insert(add);
                    cout << add.name << " is working hard now." << endl;
                }
            } else {
                if (from_lower) {
                    const Member add = *upper.begin();
                    upper.erase(add);
                    lower.insert(add);
                    cout << add.name << " is not working now." << endl;
                }
            }
        }
        day++;
    }
    return 0;
}

Measured memory_bytes: 12672