#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef pair<pii, string> Data;

priority_queue<Data> idle;
priority_queue<Data, vector<Data>, greater<Data>> work;
map<string, pair<int, bool>> mp;
int n, m;
int cnt;

void clean()
{
	while (!idle.empty())
	{
		string s = idle.top().second; int t = idle.top().first.second;
		if (mp[s].first == t) break;
		idle.pop();
	}
	while (!work.empty())
	{
		string s = work.top().second; int t = work.top().first.second;
		if (mp[s].first == t) break;
		work.pop();
	}
}

void add(string s, pii a, bool f)
{
	assert(mp.count(s) == 0 || mp[s].first == -1);
	mp[s] = make_pair(a.second, false);
	cnt++;
	idle.push(Data{ a, s });
	clean();
	if (cnt % 5 == 0)
	{
		auto tmp = idle.top();
		idle.pop();
		work.push(tmp);
		mp[tmp.second].second = true;
		if (f && tmp.second == s)
		{
			cout << tmp.second << " is working hard now." << endl;
		}
		else if(f)
		{
			cout << s << " is not working now." << endl;
			cout << tmp.second << " is working hard now." << endl;
		}
	}
	else
	{
		if (work.empty())
		{
			if(f) cout << s << " is not working now." << endl;
		}
		else
		{
			auto x = idle.top();
			auto y = work.top();
			if (x.first > y.first)
			{
				assert(x.second == s);
				idle.pop();
				work.pop();
				idle.push(y);
				work.push(x);
				mp[x.second].second = true;
				mp[y.second].second = false;
				if (f)
				{
					cout << x.second << " is working hard now." << endl;
					cout << y.second << " is not working now." << endl;
				}
			}
			else if(f)
			{
				cout << s << " is not working now." << endl;
			}
		}
	}
}

void rem(string s, bool f)
{
	assert(mp[s].first != -1);
	mp[s].first = -1;
	cnt--;
	clean();
	if (cnt % 5 == 4)
	{
		if (mp[s].second == false)
		{
			Data x = work.top();
			work.pop();
			mp[x.second].second= false;
			idle.push(x);
			if(f) cout << x.second << " is not working now." << endl;
		}
	}
	else
	{
		if (mp[s].second == true)
		{
			Data x = idle.top();
			idle.pop();
			mp[x.second].second = true;
			work.push(x);
			if(f) cout << x.second << " is working hard now." << endl;
		}
	}
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int t = 0;
	cnt = 0;
	cin >> n;
	REP(i, n)
	{
		string s; int a;
		cin >> s >> a;
		add(s, pii(a, t), false);
		t++;
	}
	cin >> m;
	REP(i, m)
	{
		char c; string s; int a;
		cin >> c >> s;
		if (c == '+')
		{
			cin >> a;
			add(s, pii(a, t), true);
		}
		else
		{
			rem(s, true);
		}
		t++;
	}
	return 0;
}


Measured memory_bytes: 10276