#include<bits/stdc++.h>
using namespace std;
#define maxn 100100
struct P1
{
	string name;
	int v,tim;
	bool operator <(const P1& pp) const 
	{
		if(v!=pp.v) return v<pp.v;
		else return tim<pp.tim;
	}
};
struct P2
{
	string name;
	int v,tim;
	bool operator <(const P2& pp) const 
	{
		if(v!=pp.v) return v>pp.v;
		else return tim>pp.tim;
	}
}a[maxn];
set<P1>s1;
set<P2>s2;
int n,m;
string man;
int v;
#define P pair<int,int>
map<string,P>mp;
P1 p2top1(P2 tmp)
{
	P1 ans;
	ans.name=tmp.name;
	ans.v=tmp.v;
	ans.tim=tmp.tim;
	return ans;
}
P2 p1top2(P1 tmp)
{
	P2 ans;
	ans.name=tmp.name;
	ans.v=tmp.v;
	ans.tim=tmp.tim;
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		a[i].tim=i;
		cin>>a[i].name;
		scanf("%d",&a[i].v);
		mp[a[i].name]=P(a[i].v,i);
	}
	sort(a+1,a+n+1);
	int lx=n/5;
	for(int i=1;i<=lx;++i) s1.insert(p2top1(a[i]));
	for(int i=lx+1;i<=n;++i) s2.insert(a[i]);
	scanf("%d",&m);
	int tot=n;
	for(int i=1;i<=m;++i)
	{
		int now=n+i;
		char op[5];
		scanf("%s",op);
		if(*op=='+')
		{
			cin>>man;
			scanf("%d",&v);
			mp[man]=P(v,now);
			tot++;
			set<P1>::iterator it;
			it=s1.begin();
			P1 tmp,this_man;
			if(it!=s1.end())
			{	
				tmp=(*it);
				this_man.name=man;this_man.v=v; this_man.tim=now;
			}
			if(it!=s1.end()&&tmp<this_man)
			{
				s1.insert(this_man);
				cout<<man;
				puts(" is working hard now.");
				if(tot%5!=0)
				{
					P1 tmp=(*it);
					P2 ttmp=p1top2(tmp);
					s1.erase(it);
					s2.insert(ttmp);
					cout<<tmp.name;
					puts(" is not working now.");
					
				}
			}
			else 
			{
				if(tot%5==0)
				{
					set<P2>::iterator it;
					it=s2.begin();
					P2 this_,tmp;
					if(it!=s2.end())
					{
						tmp=(*it);
						this_.name=man; this_.v=v; this_.tim=now;
					}
					else tmp.v=-100000;
					if(this_<tmp)
					{
						P1 cpy=p2top1(this_);
						s1.insert(cpy);
						cout<<man;
						puts(" is working hard now.");
					}
					else
					{
						s2.erase(*it);
						P1 cpy=p2top1(tmp);
						s1.insert(cpy);
						s2.insert(this_);
						cout<<man;
						puts(" is not working now.");
						cout<<tmp.name;
						puts(" is working hard now.");
					}
				}
				else 
				{
					P2 this_;
					this_.name=man; this_.v=v; this_.tim=now;
					s2.insert(this_);
					cout<<man;
					puts(" is not working now.");
				}
			}
		}
		else 
		{
			tot--;
			cin>>man;
			P sx=mp[man];
			set<P1>::iterator it;
			P1 tmp1;
			tmp1.name=man; tmp1.v=sx.first; tmp1.tim=sx.second;
			it=s1.find(tmp1);
			if(it==s1.end())
			{
				//puts("cc2");
				P2 tmp2;
				tmp2=p1top2(tmp1);
				s2.erase(tmp2);
				if(tot%5==4)
				{
					it=s1.begin();
					tmp1=(*it);
					s1.erase(it);
					tmp2=p1top2(tmp1);
					s2.insert(tmp2);
					cout<<tmp1.name;
					puts(" is not working now.");
				}
			}
			else 
			{
				//puts("cc3");
				s1.erase(it);
				if(tot%5!=4)
				{
					set<P2>::iterator it2;
					it2=s2.begin();
					//s2.erase(it2);
					P2 ss=(*it2);
					s2.erase(it2);
					P1 tt=p2top1(ss);
					s1.insert(tt);
					cout<<ss.name;
					puts(" is working hard now.");
				}
			}
		}		
	}
	return 0;
}