#include <bits/stdc++.h>
#define lddb long double
#define ll long long 			//-+ 9,223,372,036,854,775,807  = 9.2*10^18 = 2^63 - 1
#define ull unsigned long long	// +18,446,744,073,709,551,615  = 1.8*10^19 = 2^64 - 1
#define l long					//-+ 			 2,147,483,647	= 2.1*10^9  = 2^31 - 1
#define ul unisgned long		// +			 4,294,967,295	= 4.3*10^9	= 2^32 - 1
#define db double

#define ff(i,n) for(long i = 0; i < n; ++i)
#define fff(i,a,b) for(int i = a; i<=b; ++i)

using namespace std;
	long double rez[4][100006];
	
	long double dist[100006];
	
	
	long double dis(long double x, long double xx, long double yy, long double r){
		long double y=0;
		
		y=abs(sqrt(pow(r,2)+pow((x-xx),2))+yy);
		
		return y;
		
		
	}
	
	void set(){

		
		
	}
	
	
	
int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);
	long double w,h,r,q,xx,yy;
	int tip;
	long double temp=0;
	cin>>w>>h>>r>>q;
	long double min=h;
	
	ff(i,(l)q){
		
		cin>>tip;
		rez[0][i]=tip;
		if(tip==1){
			cin>>rez[1][i]>>rez[2][i];
		}
		else if(tip==2){
			cin>>rez[1][i];
		}	
		}
		
		ff(i,w+1){
			dist[i]=h;
		}
		
	
			
			
			
			
			ff(i,q){
				if(rez[0][i]==2){
				
		
				ff(j,i){
					if(rez[0][j]==1){
						ff(k,w+1){
							temp=dis(rez[1][k],rez[1][j],rez[2][j],r);
							
							if(temp<dist[k]){
							dist[k]=temp;
					        
					
						}
						
					
				
				}				
			}
		}
		
		cout<<setprecision(9)<<fixed<<dist[(int)rez[1][i]];
	}
}
		



		
			
		
	
	
	
	
	
	return 0;
}