#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    int W, H, R, Q;
    cin >> W >> H >> R >> Q;

    vector<int> grizX;
    vector<int> grizY;
    int X[W] = {0};

    for(int i = 0; i < Q; i++){
        int x;
        cin >> x;
        if(x == 1){
            int y;
            cin >> x >> y;
            grizX.push_back(x);
            grizY.push_back(y);
            if(grizY.at(X[x]) > grizY.back()) {
                X[x] = grizX.size()-1;
                for(int z = 1; z <= R; z++) {
                    if(grizY.at(X[x-z]) > grizY.back()) X[x-z] = grizX.size()-1;
                    if(grizY.at(X[x+z]) > grizY.back()) X[x+z] = grizX.size()-1;
                }
            }

        }
        else {
            cin >> x;
            if(x > W) cout << 0 << endl;
            else if(grizX.size() == 0) cout << H << endl;
            else if(grizY.at(X[x]) - sqrt((long double)R*R - (long double)pow((x - grizX.at(X[x])), 2)) > H) cout << H << endl;
            else cout << grizY.at(X[x]) - sqrt((long double)R*R - (long double)pow((x - grizX.at(X[x])), 2)) << endl;
        }
    }

    return 0;
}