#include "vector"
#include "math.h"
#include "iostream"
using namespace std;

int main()
{
    float w, h, r, q;
    float inst, xkrug = w, ykrug = h, xmerenje, ymerenje;
    vector<float> niz;
    int i, j, brmerenja=0;
    cin >> w >> h >> r >> q;
    for(i=0; i<q; i++)
    {
        cin >> inst;
        if(inst == 1)
        {
            cin >> xkrug;
            cin >> ykrug;
        }
        if(inst == 2)
        {
            brmerenja++;
            cin >> xmerenje;
            ymerenje = sqrt((r * r) - ((xmerenje - xkrug) * (xmerenje - xkrug))) + ykrug;
            if(ymerenje > h)
            {
                niz.push_back (h);
            }
            else
            {
                niz.push_back (ymerenje);
            }
        }
    }
    cout << endl;
    for(i=0; i<brmerenja; i++)
    {
        cout << niz[i] << endl;
    }
    return 0;
}