#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

string s[100000];
int v[100000];

void work() {
	cout << " is working hard now.\n";
}

void idol() {
	cout << " is not working now.\n";
}

void Use(set<pair<int, int>>&used, set<pair<int, int>>&unused) {
	auto it = prev(unused.end());
	used.insert(*it);
	cout << s[it->second];
	work();
	unused.erase(it);
}

void Unuse(set<pair<int, int>>&used, set<pair<int, int>>&unused) {
	auto it = used.begin();
	unused.insert(*it);
	cout << s[it->second];
	idol();
	used.erase(it);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	map<string, int>mp;
	set<pair<int, int>>used;
	set<pair<int, int>>unused;
	int num = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i] >> v[i];
		mp[s[i]] = i;
		num++;
		used.insert({ v[i],i });
	}
	while (used.size() > num / 5) {
		unused.insert(*used.begin());
		used.erase(used.begin());
	}
	cin >> M;
	for (int i = N; i < N + M; i++) {
		char c;
		string t;
		cin >> c >> t;
		if (c == '+') {
			cin >> K;
			s[i] = t;
			v[i] = K;
			mp[s[i]] = i;
			num++;
			if (!used.empty() && *used.begin() < make_pair(v[i], i)) {
				cout << s[i];
				work();
				used.insert({ v[i],i });
			}
			else if (num % 5 == 0 && *unused.rbegin() < make_pair(v[i], i)) {
				cout << s[i];
				work();
				used.insert({ v[i],i });
			}
			else {
				cout << s[i];
				idol();
				unused.insert({ v[i],i });
			}
		}
		else {
			auto p = make_pair(v[mp[t]], mp[t]);
			num--;
			if (used.find(p) == used.end()) {
				unused.erase(p);
			}
			else {
				used.erase(p);
			}
		}
		while (used.size() < num / 5) {
			Use(used, unused);
		}
		while (used.size() > num / 5) {
			Unuse(used, unused);
		}
		//cout << num << " " << used.size() << " " << unused.size() << endl;
	}
}
