import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(T s) {
    return cast(int)s.length;
}

struct P {
    string name;
    int x;
    int t;
    int opCmp(in P p) const {
        return (x == p.x ? t - p.t : x - p.x);
    }
}

void main() {
    int N; readf("%d\n", &N);
    auto w = new RedBlackTree!(P, "a < b");
    auto nw = new RedBlackTree!(P, "a < b");

    P[string] m;
    void insert(in string name, int x, int t, bool output) {
        auto c = P(name, x, t);
        m[name] = c;
        if (c < (w.empty ? P("", int.max, int.max) : w.front)) {
            nw.insert(c);
            if (output)
                writeln(name ~ " is not working now.");
        } else {
            w.insert(c);
            if (output)
                writeln(name ~ " is working hard now.");
        }
        int n = w.size + nw.size;
        int w_count = n / 5;
        if (w_count > w.size) {
            w.insert(nw.back);
            if (output) {
                writeln(nw.back.name ~ " is working hard now.");
            }
            nw.removeBack;
        } else if (w_count < w.size) {
            nw.insert(w.front);
            if (output) {
                writeln(w.front.name ~ " is not working now.");
            }
            w.removeFront;
        }
    }

    void remove(in string name, int t) {
        assert(name in m);
        auto c = m[name];
        int n = w.size + nw.size - 1;
        int w_count = n / 5;
        if (c in w) {
            w.removeKey(c);
            if (w_count > w.size) {
                w.insert(nw.back);
                //writeln(name ~ " is not working now.");
                writeln(nw.back.name ~ " is working hard now.");
                nw.removeBack;
            }
        } else if (c in nw) {
            nw.removeKey(c);
            if (w_count < w.size) {
                nw.insert(w.front);
                writeln(w.front.name ~ " is not working now.");
                w.removeFront;
            }
        }
    }

    foreach (int t; 0 .. N) {
        string name; int x; readf("%s %d\n", &name, &x);
        insert(name, x, t, false);
    }

    int M; readf("%d\n", &M);
    foreach (int t; N .. N + M) {
        string op, name; readf("%s ", &op);
        if (op == "+") {
            int x; readf("%s %d\n", &name, &x);
            insert(name, x, t, true);
        } else {
            readf("%s\n", &name);
            remove(name, t);
        }
    }
}