Problem

Today, the Earth has been attacked by the invaders from space, Invader, and the only survivors of humankind are us at the base. There is almost no force left to compete with them. But here we do not give up. Eradication of Invaders is the last resort for us humans to survive. I will explain the contents of the strategy that will be the last from now on.

First of all, our strength is too small compared to the strength of the Invader, so we will stay at this base and fight the siege. Surrounded by high mountains, the base has no choice but to take a straight road in front of the base for the invaders to invade. We will call this road a field. With this feature, it is possible to concentrate on the front and attack the invader. At the base, we attack the Invader with two types of weapons. One is a sniper rifle that snipers one invader. The other is a grenade launcher that can attack over a wide area.

As the only programmer in humanity, your job is to simulate combat based on Invaders and our action records. Action records are given in query format. Each query consists of one or more integers and is given as follows:

0 | Invaders appear on the field at a distance of L from the base.
--- | ---
1 d | All invaders currently on the field approach the base by d. After this action, the invaders that reach the base will take damage, and their enemies will disappear from the field. If it is damaged, "damage (the number of invaders that reached the base at this time)" is output on one line.
2 k | If the number of invaders currently on the field is k or more, attack the kth invader from the closest to the base with a sniper rifle. The invader disappears from the field. And output "hit" on one line. If the number of invaders on the field is less than k, print "miss" on one line.
3 x r | Attack with a grenade launcher in the range r at a position x from the base. All invaders that land at a distance of x from the base and are less than or equal to r will disappear from the field. Then output "bomb (number of invaders killed)" on one line. As a side note, the base will not be damaged by the grenade launcher.
4 k | If the number of invaders on the field is k or more, output "distance (distance between the kth invader from the closest base to the base)" on one line. If the number of invaders on the field is less than k, print "distance -1" on one line.




That is all for the explanation of the strategy. All members start the operation! ... Good luck.

Constraints

The input satisfies the following conditions.

* All values ​​contained in the input are integers
* 1 ≤ Q ≤ 100000
* 1 ≤ L ≤ 109
* 1 ≤ d, k ≤ 109
* 0 ≤ x ≤ L
* 0 ≤ r ≤ 109
* There can never be more than one invader in the same position
* No more than 3 datasets

Input

The input consists of multiple datasets. Each dataset is represented below. The first line is given two integers Q and L separated by spaces. The following Q line is given the Q queries described above. The end of the input consists of two zeros.

Output

For each dataset, output for queries that have output instructions. Print "end" at the end of each dataset.

Example

Input

18 10
0
4 1
1 1
4 1
0
1 1
0
2 2
1 10
0
1 1
0
1 1
0
1 5
3 4 0
3 4 1
0
9 10
4 1
2 2
3 5 5
0
4 1
2 2
3 5 5
0
2 1
0 0


Output

distance 10
distance 9
hit
damage 2
bomb 1
bomb 2
end
distance -1
miss
bomb 0
distance 10
miss
bomb 1
hit
end
#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;
}