#include<bits/stdc++.h>
using namespace std;
 
#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
struct BIT{
    int N;
    vint dat;
    void init(int n){
        N=n;
        dat.resize(N+1);
    }
    void add(int k,int x){
        for(k++;k<=N;k+=k&-k)dat[k]+=x;
    }
    int sum(int k){
        int ret=0;
        for(k++;k;k-=k&-k)ret+=dat[k];
        return ret;
    }
};
 
int N,M;
 
string name[100000];
int start[50000];
int type[20000],id[20000];
bool working[100000];
 
signed main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
 
    cin>>N;
    vector<pint>vec;
 
    string SS[50000];int TT[50000];
    map<string,int>mp;
    rep(i,N){
        cin>>SS[i]>>TT[i];
        vec.pb(pint(TT[i],i));
        mp[SS[i]]=i;
    }
    char CCC[20000];
    string SSS[20000];
    int TTT[20000];
    cin>>M;
    rep(i,M){
        cin>>CCC[i]>>SSS[i];
        if(CCC[i]=='+'){
            cin>>TTT[i];
            vec.pb(pint(TTT[i],i+N));
            mp[SSS[i]]=i+N;
        }
        else{
            if(mp.find(SSS[i])==mp.end())abort();
            TTT[i]=mp[SSS[i]];
        }
    }
    sort(all(vec));reverse(all(vec));
    rep(i,vec.size()){
        int j=vec[i].se;
        if(j<N){
            start[j]=i;
            name[i]=SS[j];
        }
        else{
            id[j-N]=i;
            name[i]=SSS[j-N];
        }
    }
    rep(i,M){
        if(CCC[i]=='+'){
            type[i]=1;
        }
        else{
            type[i]=-1;
            int j=TTT[i];
            if(j<N)id[i]=start[j];
            else id[i]=id[j-N];
        }
    }
 
    BIT bit;bit.init(N+M+114);
    rep(i,N)bit.add(start[i],1);
    int curSize=N;
    int curLim=curSize/5;
    int curWorking=curLim;
    rep(i,N)if(bit.sum(start[i])<=curLim)working[start[i]]=true;
 
    rep(i,M){
        if(type[i]==1){
            bit.add(id[i],1);
            assert(working[id[i]]==false);
            curSize++;
            curLim=curSize/5;
 
            if(bit.sum(id[i])<=curLim){
                curWorking++;
                working[id[i]]=true;
                cout<<name[id[i]]<<" is working hard now."<<endl;
            }
            else{
                cout<<name[id[i]]<<" is not working now."<<endl;
            }
        }
        else{
            bit.add(id[i],-1);
            curSize--;
            curLim=curSize/5;
            if(working[id[i]]){
                working[id[i]]=false;
                curWorking--;
            }
        }
 
        if(curWorking<curLim){
            int lb=-1,ub=vec.size();
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                if(bit.sum(mid)<curLim)lb=mid;
                else ub=mid;
            }
            //assert(working[ub]==false);
            working[ub]=true;
            cout<<name[ub]<<" is working hard now."<<endl;
            curWorking++;
        }
        else if(curWorking>curLim){
            int lb=-1,ub=vec.size();
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                if(bit.sum(mid)<curWorking)lb=mid;
                else ub=mid;
            }
            working[ub]=false;
            cout<<name[ub]<<" is not working now."<<endl;
            curWorking--;
        }
    }
    return 0;
}

Measured memory_bytes: 13824