#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
typedef pair<LL, int> P;

inline LL eval(P p, const vector<LL>& sum, LL C) {
    return p.first + sum[p.second] - C;
}
inline int lower_bound(LL l, const deque<P>& s, const vector<LL>& sum, LL C) {
    int lb = -1, ub = s.size();
    while(ub - lb > 1) {
        int k = (lb + ub) / 2;
        if(eval(s[k], sum, C) >= l) {
            ub = k;
        } else {
            lb = k;
        }
    }
    return ub;
}

int main(){
    int Q;
    LL L;
    while(cin >> Q >> L && Q > 0) {
        LL C = 0;
        vector<LL> sum(Q);
        deque<P> s;
        for(int i = 0; i < Q; i++) {
            int type;
            scanf("%d", &type);

            if(type == 0) {
                s.push_back(P(L, i));
            } else if(type == 1) {
                LL D;
                scanf("%lld", &D);
                C += D;
                int ans = 0;
                while(s.size()) {
                    P p = s.front();
                    if(eval(p, sum, C) <= 0) {
                        ans++;
                        s.pop_front();
                    } else {
                        break;
                    }
                }
                if(ans > 0) {
                    cout << "damage ";
                    cout << ans << endl;
                }
            } else if(type == 2) {
                int k;
                scanf("%d", &k);
                if(s.size() >= k) {
                    k--;
                    s.erase(s.begin() + k);
                    cout << "hit" << endl;
                } else {
                    cout << "miss" << endl;
                }
            } else if(type == 3) {
                LL x, r;
                scanf("%lld %lld", &x, &r);
                LL a = x - r, b = x + r; // [a, b]
                //cout << "[" << a << ", " << b << "]" << endl;
                int begin = lower_bound(a, s, sum, C);
                auto it = s.begin() + begin;
                int ans = 0;
                while(it != s.end()) {
                    auto dist = eval(*it, sum, C);
                    if(dist > b) break;
                    ans++;
                    assert(dist >= a);
                    it = s.erase(it);
                }
                cout << "bomb " << ans << endl;
            } else if(type == 4) {
                int k;
                scanf("%d", &k);
                if(s.size() >= k) {
                    k--;
                    cout << "distance ";
                    cout << eval(s[k], sum, C) << endl;
                } else {
                    cout << "distance -1" << endl;
                }
            }

            sum[i] = C;
        }
        cout << "end" << endl;
    }
    return 0;
}