#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 + 1);
		}
	}

	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]?????´??°??????. ?????????1-indexed.
	void update(int l, int r, Value2 v, int k = 1, int a = 1, 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 + 1, b);
		update_node(k);
	}
	//get(l,r) := [l,r]?????????????????¨?????????????????????. ?????????1-indexed.
	Value1 get(int l, int r, int k = 1, int a = 1, 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 + 1, 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] + 1, cp.mp[nowx + L] + 1, make_pair(0, 1));
				break;
			case 1: {

				int damage = seg.get(cp.mp[nowx] + 2, cp.mp[nowx + q.a] + 1);
				seg.update(cp.mp[nowx] + 2, 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] + 2, cp.mp[nowx] + 2 + amid) >= q.a) {
						amax = amid;
					}
					else {
						amin = amid;
					}
				}
				if (amax != 3e5) {
					cout << "hit" << endl;
					seg.update(cp.mp[nowx] + 2+ 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] + 1, cp.mp[q.b] + 1);
				cout << "bomb " << bomb << endl;
				seg.update(cp.mp[q.a] + 1, 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] + 2, 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;
}

Measured memory_bytes: 31344