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"
using namespace std;


typedef int Value1;
typedef pair<bool,int>Value2;
const Value1 Zero1(0);
const Value2 Zero2(make_pair(false, 0));

struct Node {
	Value1 sum;//??´??°????????????. ?????????????????§??????????????????????????¨????????????????????????????????????.
	Value2 lazy;	//?????¶???????????????????????????????????????
	Node() :sum(Zero1) {
		lazy = Zero2;
	}
};
struct lazy_segtree {
	int N;
	vector<Node>dat;
	lazy_segtree(int n) :N(1) {
		while (N < n) N *= 2;
		dat.resize(2 * N);
	}

	Value2 lazy_connect(const Value2 l, const Value2 r) {
		if (l.first || r.first)return make_pair(1, -1);
		else {
			return make_pair(0, l.second + r.second);
		}
	}

	void lazy_func(const int k, const int a, const int b) {
		if (dat[k].lazy.first)dat[k].sum = 0;
		else {
			dat[k].sum += dat[k].lazy.second*(b - a);
		}
	}

	Value1 connect(const Value1 l, const Value1 r) {
		return l + r;

	}

	// inline??????????????¨??§???????????¨????????????!(??????)
	inline void lazy_evaluate_node(int k, int a, int b) {
		lazy_func(k, a, b);
		if (k < N) { // 2*k(???????????????) < 2*N (???????????°) ?????????????????§. ???????????????????????????????????¬???????????¨??????.
			dat[2 * k].lazy = lazy_connect(dat[2 * k].lazy, dat[k].lazy);	//?¬???????????????¬??????????????£?????????.
			dat[2 * k + 1].lazy = lazy_connect(dat[2 * k + 1].lazy, dat[k].lazy);
		}
		dat[k].lazy = Zero2;
	}

	inline void update_node(int k) { // k???????????¢?????????????????????????????¨?????????. ????????\????????¨????????????????????????????????????????????????????????§if???????????????.
		dat[k].sum = connect(dat[2 * k].sum, dat[2 * k + 1].sum);

	}

	// update(l,r,v) := [l,r)?????´??°??????. ?????????0-indexed.
	void update(int l, int r, Value2 v, int k = 1, int a = 0, int b = -1) {
		if (b == -1)b = N;
		if (l < 0 || r < 0)assert(false);
		lazy_evaluate_node(k, a, b); 	// ??¨?????????????????£???????????????????????????????????§?????¬?????¨???????\?.

		if (b <= l || r <= a) //[a,b)??¨[l,r)???????????????????????´???
			return;
		if (l <= a && b <= r) { // [l,r)???[a,b)????????¨???????????§????????´???
			dat[k].lazy = lazy_connect(dat[k].lazy, v);
			lazy_evaluate_node(k, a, b); //???????????¶???????????¨???????????¨?????????????????§.
			return;
		}

		int m = (a + b) / 2;
		update(l, r, v, 2 * k, a, m);
		update(l, r, v, 2 * k + 1, m, b);
		update_node(k);
	}
	//get(l,r) := [l,r)?????????????????¨?????????????????????. ?????????0-indexed.
	Value1 get(int l, int r, int k = 1, int a = 0, int b = -1) {
		if (b == -1)b = N;
	
		if (l < 0 || r<0)assert(false);
		lazy_evaluate_node(k, a, b); // ??¨?????????????????£???????????????????????????????????§?????¬?????¨???????\?.
	
		if (b <= l || r <= a) //[a,b)??¨[l,r)???????????????????????´???
			return Zero1;
	
		if (l <= a && b <= r) { // [l,r)???[a,b)????????¨???????????§????????´???
			return dat[k].sum;
		}
	
		int m = (a + b) / 2;
		Value1 vl = get(l, r, 2 * k, a, m);
		Value1 vr = get(l, r, 2 * k + 1, m, b);
		update_node(k);
		return connect(vl, vr);
	}
};

struct query {
	int type;
	long long int a;
	long long int b;
};
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}

};

int main() {
	int Q;
	while (cin>>Q,Q) {


		long long int L; cin >> L;
		Compress<long long int> cp;
		vector<query>qs;
		{

			vector<long long int>xs;
			xs.push_back(0);
			long long int nowdis = 0;
			for (int i = 0; i < Q; ++i) {
				int a; cin >> a;
				if (a == 0) {
					xs.push_back(nowdis + L);
					qs.push_back(query{ a,-1,-1 });
				}
				else if (a == 1) {
					int d; cin >> d;
					nowdis += d;
					xs.push_back(nowdis);
					qs.push_back(query{ a,d,-1 });
				}
				else if (a == 2) {
					int k; cin >> k;
					qs.push_back(query{ a,k,-1 });
				}
				else if (a == 3) {
					int x, r; cin >> x >> r;
					xs.push_back(nowdis + x + r);
					xs.push_back(nowdis + x - r);
					qs.push_back(query{ a,nowdis + x - r,nowdis + x + r });
				}
				else if (a == 4) {
					int k; cin >> k;
					qs.push_back(query{ a,k,-1 });
				}
			}
			cp.setmp(xs);
			
		}
		lazy_segtree seg(cp.mp.size());
		long long int nowx = 0;
		for (auto q : qs) {
			switch (q.type) {
			case 0:
				seg.update(cp.mp[nowx + L], cp.mp[nowx + L] + 1, make_pair(0, 1));
				break;
			case 1: {

				int damage = seg.get(cp.mp[nowx] + 1, cp.mp[nowx + q.a] + 1);
				seg.update(cp.mp[nowx], cp.mp[nowx + q.a] + 1, make_pair(1, 0));
				if (damage) {
					cout << "damage" << " " << damage << endl;
				}
				nowx += q.a;
			}
					break;
			case 2:
			{
				int amin = -1;
				int amax = 3e5;
				while (amin + 1 != amax) {
					int amid((amin + amax) / 2);
					if (seg.get(cp.mp[nowx] + 1, cp.mp[nowx] + 2 + amid) >= q.a) {
						amax = amid;
					}
					else {
						amin = amid;
					}
				}
				if (amax != 3e5) {
					cout << "hit" << endl;
					seg.update(cp.mp[nowx] + 1+ amax, cp.mp[nowx] + 2+ amax, make_pair(0, -1));
				}
				else {
					cout << "miss" << endl;
				}
			}
			break;
			case 3:
			{

				int bomb = seg.get(cp.mp[q.a], cp.mp[q.b] + 1);
				cout << "bomb " << bomb << endl;
				seg.update(cp.mp[q.a], cp.mp[q.b] + 1, make_pair(1, 0));
			}
			break;
			case 4:
			{
				int amin = -1;
				int amax = 3e5;
				while (amin + 1 != amax) {
					int amid((amin + amax) / 2);
					if (seg.get(cp.mp[nowx] + 1, cp.mp[nowx] + 2 + amid) >= q.a) {
						amax = amid;
					}
					else {
						amin = amid;
					}
				}
				if (amax != 3e5) {
					long long int dis = cp.revmp[cp.mp[nowx] +1+ amax] - nowx;
					cout << "distance " << dis << endl;

				}
				else {
					cout << "distance -1" << endl;
				}
			}
			break;
			default:
				assert(false);
				break;
			}
		}
		cout << "end" << endl;
		assert(cp.mp.size() == cp.revmp.size());
	}
	return 0;
}