using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inp1 = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
            // inp1[0] - W, inp1[1] - H, inp1[2] - R, inp1[3] - Q(narednih linija)
            var CircleDotsX = new System.Collections.Generic.List<int>();
            var CircleDotsY = new System.Collections.Generic.List<int>();
            int[] ars;
            var Outputs = new System.Collections.Generic.List<double>();

            for (int i = 0; i < inp1[3]; i++)
            {
                ars = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt32);
                if (ars[0] == 1)
                {
                    CircleDotsX.Add(ars[1]);
                    CircleDotsY.Add(ars[2]);
                } else
                {
                    if(CircleDotsX.Count == 0)
                    {
                        Outputs.Add(inp1[1]);
                        continue;
                    }
                    int tempIndx = 0;
                    for (int j = 0; j < CircleDotsX.Count; j++)
                    {
                        if (Math.Sqrt(Math.Pow((CircleDotsX[j] - ars[1]), 2) + Math.Pow((CircleDotsY[j]), 2)) < Math.Sqrt(Math.Pow((CircleDotsX[tempIndx] - ars[1]), 2) + Math.Pow((CircleDotsY[tempIndx]), 2)))
                        {
                            tempIndx = j;
                        }
                    }

                    int x = Math.Abs(ars[1] - CircleDotsX[tempIndx]);

                    double y = inp1[2] - Math.Sqrt(Math.Pow(inp1[2], 2) - Math.Pow(x, 2));
                    int z = CircleDotsY[tempIndx] - inp1[2];

                    if (z < 0) {
                        Outputs.Add(0);
                    } else if (inp1[3] + inp1[2] <= CircleDotsY[tempIndx])
                    {
                        Outputs.Add(inp1[1]);
                    } else if (Math.Abs(CircleDotsX[tempIndx] - ars[1])  >= inp1[2])
                    {
                        Outputs.Add(inp1[1]);
                    }
                    else 
                    {
                        Outputs.Add(y + z);
                    }   
                }

            }


            foreach (var x in Outputs)
            {
                Console.WriteLine(x);
            }
        }
    }
}