#include<bits/stdc++.h>
using namespace std;

class BIT {
public:
    int n;
    vector<int> bit;
    BIT(int _n) {
        n = _n;
        bit.clear();
        bit.resize(n, 0);
    }
    void add(int j, int w) {
        for (int i = j; i < n; i |= i + 1)
            bit[i] += w;
    }
    int sum(int j) {
        int ret = 0;
        for (int i = j - 1; i >= 0; i = (i & (i + 1)) - 1) {
            ret += bit[i];
        }
        return ret;
    }
    int sum(int j, int k) {
        return sum(k) - sum(j);
    }
    int lowerbound(int a) {
        int l = 0, r = n;
        while (l < r) {
            int m = (l + r) >> 1;
            if (sum(m) < a) {
                if (sum(m + 1) >= a) return m + 1;
                l = m + 1;
            }
            else r = m - 1;
        }
        if (sum(l) < a) return l + 1;
        return l;
    }
};

int main() {
    int n;
    cin >> n;
    vector<pair<string, long long>> inp;
    for (int i = 0; i < n; ++i) {
        string s;
        long long p;
        cin >> s >> p;
        inp.push_back(make_pair(s, p));
    }
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        char c;
        string s;
        cin >> c >> s;
        if (c == '+') {
            long long p;
            cin >> p;
            inp.push_back(make_pair(s, p));
        }
        else {
            inp.push_back(make_pair(s, -1LL));
        }
    }
    set<long long> se;
    for (int i = 0; i < n + m; ++i) {
        if (inp[i].second == -1) continue;
        inp[i].second = inp[i].second * (n + m) + i;
        se.insert(inp[i].second);
    }
    map<long long, int> _mp;
    int c = n + m + 5;
    for (auto i : se) {
        _mp[i] = --c;
    }
    map<string, int> mp;
    vector<string> getname(n + m + 9);
    BIT bit(n + m + 9);
    for (int i = 0; i < n; ++i) {
        mp[inp[i].first] = _mp[inp[i].second];
        getname[mp[inp[i].first]] = inp[i].first;
        bit.add(mp[inp[i].first], 1);
    }
    int sz = n;
    int lowwork = bit.lowerbound(sz / 5) - 1;
    for (int i = n; i < n + m; ++i) {
        if (inp[i].second != -1) {
            mp[inp[i].first] = _mp[inp[i].second];
            getname[mp[inp[i].first]] = inp[i].first;
            bit.add(mp[inp[i].first], 1);
            ++sz;
            int lw = bit.lowerbound(sz / 5) - 1;
            if (mp[inp[i].first] <= lw) {
                cout << inp[i].first << " is working hard now.\n";
            }
            else {
                cout << inp[i].first << " is not working now.\n";
            }
            if (lw != lowwork) {
                if (lw > lowwork) {
                    if (inp[i].first != getname[lw])
                        cout << getname[lw] << " is working hard now.\n";

                }
                else {
                    cout << getname[lowwork] << " is not working now.\n";
                }

                lowwork = lw;
            }
        }
        else {
            bit.add(mp[inp[i].first], -1);
            --sz;
            int lw = bit.lowerbound(sz / 5) - 1;
            if (lw != lowwork) {
                if (lw > lowwork) {
                    cout << getname[lw] << " is working hard now.\n";
                }
                else {
                    if (inp[i].first != getname[lowwork])
                        cout << getname[lowwork] << " is not working now.\n";
                }

                lowwork = lw;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 18376