#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ll val = 100000;
int main() {
	int n, m;
	map<string,ll> mp;
    map<ll, string> invmp;
	set<ll> st;
	string nam; ll mot;
	cin >> n;
	rep(i, n) {
		cin >> nam >> mot; mot *= val; mot += (ll)i;
		mp[nam] = mot;
		invmp[mot] = nam;
		st.insert(mot);
	}
	int cnt = n;
	std::set<ll>::iterator itr = st.end();
	rep(i, n / 5) {
		--itr;
	}
	--itr;
	ll now = *itr;
	cin >> m; char t;
	Rep(i,n, n+m) {
		cin >> t;
		if (t == '+') {
			cin >> nam >> mot; mot *= val; mot += (ll)i;
			if (cnt == 0) {
				cnt++;
				now = mot;
				st.insert(mot);
				mp[nam] = mot;
				invmp[mot] = nam;
				cout << nam << " is not working now." << endl;
				continue;
			}
			cnt++;
			if (cnt / 5 == (cnt - 1) / 5) {
				st.insert(mot);
				mp[nam] = mot;
				invmp[mot] = nam;
				std::set<ll>::iterator itra = st.find(now);
				++itra;
				if (itra != st.end()) {
					ll nex = *itra;
					if (nex < mot) {
						now = nex;
						cout << nam << " is working hard now." << endl;
						cout << invmp[nex] << " is not working now." << endl;
					}
					else if(nex>mot){
						cout << nam << " is not working now." << endl;
					}
					else {
						cout << nam << " is not working now." << endl;
						now = nex;
					}
				}
				else {
					cout << nam << " is not working now." << endl;
				}
			}
			else {
				st.insert(mot);
				mp[nam] = mot;
				invmp[mot] = nam;
				if (now < mot) {
					cout << nam << " is working hard now." << endl;
				}
				else{
					cout << nam << " is not working now." << endl;
					cout<<invmp[now]<< " is working hard now." << endl;
					std::set<ll>::iterator itra = st.find(now);
					--itra; now = *itra;
				}
			}
		}
		else {
			cnt--;
			cin >> nam;
			if (cnt / 5 == (cnt + 1) / 5) {
				if (now < mp[nam]) {
					cout<<invmp[now]<< " is working hard now." << endl;
					std::set<ll>::iterator itra = st.find(now);
					--itra; now = *itra;
					st.erase(mp[nam]); invmp.erase(mp[nam]); mp.erase(nam);
				}
				else if(now>mp[nam]){
					st.erase(mp[nam]); invmp.erase(mp[nam]); mp.erase(nam);
				}
				else {
					std::set<ll>::iterator itra = st.find(now);
					if (itra != st.begin()) {
						--itra; now = *itra;
						st.erase(mp[nam]); invmp.erase(mp[nam]); mp.erase(nam);
					}
				}
			}
			else {
				if (now < mp[nam]) {
					st.erase(mp[nam]); invmp.erase(mp[nam]); mp.erase(nam);
				}
				else {
					std::set<ll>::iterator itra = st.find(now);
					++itra; now = *itra;
					cout << invmp[now] << " is not working now." << endl;
					st.erase(mp[nam]); invmp.erase(mp[nam]); mp.erase(nam);
				}
			}
		}
	}
	return 0;
}

