#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int w, h, r, q;
    cin >> w >> h >> r >> q;
    int matrix[q][3];
    for (int i = 0; i < q; ++i){
        cin >> matrix[i][1] >> matrix[i][2];
        if (matrix[i][1] == 1)
            cin >> matrix[i][3];
        else
            matrix[i][3] = -1;
    }

    double keks[w+1];
    for (int i = 0; i <= w; ++i){
        keks[i] = h;
    }

    double vilica[r+1];
    for (int i = 0; i <= r; ++i){
        vilica[i] = r - sqrt(r*r - i*i);
    }

    int d;
    double temp;
    for (int i = 0; i < q; ++i){
        if (matrix[i][1] == 1){
            for (int j = 0; j <= w; ++j){
                d = abs(matrix[i][2] - j);
                if (d > r)
                    continue;

                temp = vilica[d] + matrix[i][3] - h;
                if (temp < keks[j])
                    keks[j] = temp;
            }
        } else {
            cout << keks[matrix[i][2]] << endl;
        }
    }

    return 0;
}