#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!
 
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);
 
typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef vector<vector<int>> Graph;
 
struct Person {
    string name;
    int motiv;
    int num;
    Person(){}
    Person(string _name, int _motiv, int _num)
        : name(_name), motiv(_motiv), num(_num) {}
    bool operator< (const Person& p) const { // low rank meens high motivation
        return (this->motiv != p.motiv) ? this->motiv > p.motiv : this->num > p.num;
    }
};
 
struct Query {
    char type;
    Person person;
    Query(){}
    Query(char _type, string _name, int _motiv, int _num)
        : type(_type), person(_name, _motiv, _num) {}
};
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int n;
    cin >> n;
    vector<Person> original_members;
    map<Person, int> person_to_rank;
    map<int, Person> rank_to_person;
    map<string, int> name_to_motiv;
    map<string, int> name_to_num;
    rep(i, n) {
        string name;
        int motiv;
        cin >> name >> motiv;
        original_members.emplace_back(name, motiv, i);
        person_to_rank[Person(name, motiv, i)] = 0;
        name_to_motiv[name] = motiv;
        name_to_num[name] = i;
    }
 
    vector<Query> queries;
    int m;
    cin >> m;
    int _num = n;
    rep(i, m) {
        char type;
        string name;
        cin >> type >> name;
        int motiv;
        int num;
        if (type == '+') {
            cin >> motiv;
            name_to_motiv[name] = motiv;
            num = _num;
            name_to_num[name] = num;
            person_to_rank[Person(name, motiv, num)] = 0;
            _num++;
        } else {
            motiv = name_to_motiv[name];
            num = name_to_num[name];
        }
        queries.emplace_back(type, name, motiv, num);
        // cerr << type << " " << name << " " << motiv << " " << num << endl;
    }
 
    {
        int t = 0;
        for (auto& p : person_to_rank) {
            p.second = t++;
            // cerr << p.first.name << " " << p.first.motiv << " " << p.first.num << " " << p.second << endl;
        }
        for (auto p : person_to_rank) {
            rank_to_person[p.second] = p.first;
        }
    }
 
    set<int> working;
    set<int> neet;
    for (auto person : original_members) {
        int x = person_to_rank[person];
        neet.insert(x);
    }
    auto valid = [&](){
        return working.size() == (working.size() + neet.size()) / 5;
    };
    while (!valid()) {
        int x = *neet.begin();
        neet.erase(x);
        working.insert(x);
    }
 
    auto Work = [&](int x) {
        cout << rank_to_person[x].name << " is working hard now." << endl;
    };
    auto Neet = [&](int x) {
        cout << rank_to_person[x].name << " is not working now." << endl;
    };
 
    for (auto q : queries) {
        // cerr << endl;
        // cerr << "working:";
        // for (auto x : working) cerr << " " << x;
        // cerr << endl;
        // cerr << "neet:";
        // for (auto x : neet) cerr << " " << x;
        // cerr << endl;
 
        int x = person_to_rank[q.person];
        // cerr << "query's person = " << x << endl;
        // cerr << q.person.name << " " << q.person.motiv << " " << q.person.num << endl;
 
        if (q.type == '+') {
            if ((working.size() + neet.size()) % 5 != 4) { // neet: +1
                neet.insert(x);
                if (working.empty()) {
                    // cerr << "A" << endl;
                    Neet(x);
                    continue;
                }
                int a = *prev(working.end());
                if (x < a) {
                    // cerr << "B" << endl;
                    neet.erase(x);
                    working.erase(a);
                    working.insert(x);
                    neet.insert(a);
                    Work(x);
                    Neet(a);
                }
                else {
                    // cerr << "C" << endl;
                    Neet(x);
                }
            }
            else { // work: +1
                working.insert(x);
                if (neet.empty()) continue;
                int a = *neet.begin();
                if (a < x) {
                    // cerr << "D" << endl;
 
                    working.erase(x);
                    neet.erase(a);
                    neet.insert(x);
                    working.insert(a);
                    Neet(x);
                    Work(a);
                }
                else {
                    // cerr << "E" << endl;
 
                    Work(x);
                }
            }
        }
        if (q.type == '-') {
            if (x < *neet.begin()) {
                working.erase(x);
                if (!valid()) {
                    // cerr << "F" << endl;
                    // cerr << working.size() << " " << neet.size() << endl;
 
                    int a = *neet.begin();
                    neet.erase(a);
                    working.insert(a);
                    Work(a);
                }
            }
            else {
                neet.erase(x);
                if (!valid()) {
                    // cerr << "G" << endl;
 
                    int a = *prev(working.end());
                    working.erase(a);
                    neet.insert(a);
                    Neet(a);
                }
            }
        }
    }
}

Measured memory_bytes: 26788