#include <cstdio>
#include <cstdlib>
#include <functional>
#include <ctime>
using namespace std;

template <class D, class C = less<D> >
struct treap{
	struct node{
		friend class treap;

		D data;
	private:
		int priority;
		int count;
		node *left, *right;

		explicit node(const D &d)
		: data(d), priority(rand()), count(1), left(0), right(0)
		{}
	};

	C comparer;
	node *root;

	explicit treap(const C &c = C()): comparer(c), root(0) {}

	~treap(){ destruct(root); }

	int size(){ return root ? root->count : 0; }
	
	void insert(const D &d){
		root = insert(root, d);
	}

	void erase(const D &d){
		root = erase(root, d);
	}

	node *lower_bound(const D &d){
		node *ret = 0;
		node *next = root;
		while(next){
			node *nd = next;
			if(comparer(nd->data, d)){
				next = nd->right;
			}
			else{
				ret = nd;
				next = nd->left;
			}
		}
		return ret;
	}
	
	node *find(const D &d){
		node *ret = lower_bound(d);
		if(comparer(ret->data, d) || comparer(d, ret->data)){
			ret = 0;
		}
		return ret;
	}
	
	node *nth(int n){
		return nth(root, n);
	}
	
	node *min_element(){
		node *nd = root, *next = root;
		while(next){
			nd = next;
			next = nd->left;
		}
		return nd;
	}

private:
	void destruct(node *nd){
		if(nd){
			destruct(nd->left);
			destruct(nd->right);
			delete nd;
		}
	}

	void update(node *nd){
		int l = nd->left ? nd->left->count : 0;
		int r = nd->right ? nd->right->count : 0;
		nd->count = l + r + 1;
	}
	
	node *insert(node *nd, const D &d){
		if(!nd){ return new node(d); }
		if(comparer(d, nd->data)){
			nd->left = insert(nd->left, d);
			if(nd->priority > nd->left->priority){
				nd = rotate_right(nd);
			}
		}
		else if(comparer(nd->data, d)){
			nd->right = insert(nd->right, d);
			if(nd->priority > nd->right->priority){
				nd = rotate_left(nd);
			}
		}
		update(nd);
		return nd;
	}
	
	node *rotate_right(node *nd){
		node *lf = nd->left;
		nd->left = lf->right;
		lf->right = nd;
		update(nd);
		update(lf);
		return lf;
	}
	
	node *rotate_left(node *nd){
		node *rg = nd->right;
		nd->right = rg->left;
		rg->left = nd;
		update(nd);
		update(rg);
		return rg;
	}
	
	node *erase(node *nd, const D &d){
		if(nd){
			if(comparer(d, nd->data)){
				nd->left = erase(nd->left, d);
			}
			else if(comparer(nd->data, d)){
				nd->right = erase(nd->right, d);
			}
			else{
				if(!nd->left && !nd->right){
					delete nd;
					return 0;
				}
				
				if(!nd->left){
					nd = rotate_left(nd);
				}
				else if(!nd->right){
					nd = rotate_right(nd);
				}
				else{
					if(nd->left->priority < nd->right->priority){
						nd = rotate_right(nd);
					}
					else{
						nd = rotate_left(nd);
					}
				}
				nd = erase(nd, d);
			}
		}
		update(nd);
		return nd;
	}
	
	node *nth(node *nd, int n){
		if(!nd || n < 0 || n >= nd->count){ return 0; }
		int cl = nd->left ? nd->left->count : 0;
		if(n < cl){ return nth(nd->left, n); }
		if(n > cl){ return nth(nd->right, n - cl - 1); }
		return nd;
	}
};


typedef long long LL;

int main(){
	srand(time(0));

	int q, L, t, d, k, x, r;
	while(scanf("%d%d", &q, &L), q){
		LL b = 0;
		treap<LL> tr;
		treap<LL>::node *nd = 0;

		for(int i = 0; i < q; ++i){
			scanf("%d", &t);
			if(t == 0){
				tr.insert(L + b);
			}
			else if(t == 1){
				scanf("%d", &d);
				b += d;
				
				int c = 0;
				while(nd = tr.min_element()){
					if(nd->data > b){ break; }
					++c;
					tr.erase(nd->data);
				}
				
				if(c){ printf("damage %d\n", c); }
			}
			else if(t == 2){
				scanf("%d", &k);
				nd = tr.nth(k - 1);
				if(nd){
					puts("hit");
					tr.erase(nd->data);
				}
				else{
					puts("miss");
				}
			}
			else if(t == 3){
				scanf("%d%d", &x, &r);
				int c = 0;
				while(nd = tr.lower_bound(b + x - r)){
					if(nd->data > b + x + r){ break; }
					++c;
					tr.erase(nd->data);
				}
				printf("bomb %d\n", c);
			}
			else{
				scanf("%d", &k);
				nd = tr.nth(k - 1);
				printf("distance %lld\n", nd ? nd->data - b : -1LL);
			}
		}
		puts("end");
	}
}

Measured memory_bytes: 3224