h,w,n,d=map(int,input().split()) a=[[-1]*w for i in range(h)] s=[] r=list(range(n)) def union(x,y): rx=root(x) ry=root(y) if rx>ry: rx,ry=ry,rx r[ry]=rx return def root(x): p=x l=[p] while r[p]!=p: p=r[p] l.append(p) for p in l: r[p]=l[-1] return r[x] for i in range(n): x,y=map(int,input().split()) x-=1 y-=1 a[x][y]=i s+=[(x,y)] for dx in range(-d,d+1): for dy in range(-d,d+1): xx=x+dx yy=y+dy if 0<=xx