#include <iostream>
#include <math.h>
#include <algorithm>
#include <climits>
using namespace std;
#define length 100000
int main() {
int a[length];
for(long long i=1;i<=length;i++)
{
a[i-1]=((i%12345)*(i%12345))%12345+((i%23456)*(i%23456)%23456*i%23456)%23456; //заполнение массива
}
int k,x,y,result;
cin>>k;
int mmax,mmin; //переменные для хранения максимума и минимума на отрезке
for(int i=0;i<k;i++)
{
cin >> x >> y;
mmax=INT_MIN;
mmin=INT_MAX;
if(x>0)
{
for(int i=x-1;i<y;i++) //поиск максимума и минимума на отрезке [x,y]
{
if(mmax<a[i]) mmax=a[i];
if(mmin>a[i]) mmin=a[i];
}
cout << mmax-mmin << endl;
}
else
{
x*=-1;
a[x-1]=y; //замена x-го элемента на y
}
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8Y2xpbWl0cz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsZW5ndGggICAgMTAwMDAwCgoKCmludCBtYWluKCkgewogICBpbnQgYVtsZW5ndGhdOwogICBmb3IobG9uZyBsb25nIGk9MTtpPD1sZW5ndGg7aSsrKQogICB7CiAgICAgICBhW2ktMV09KChpJTEyMzQ1KSooaSUxMjM0NSkpJTEyMzQ1KygoaSUyMzQ1NikqKGklMjM0NTYpJTIzNDU2KmklMjM0NTYpJTIzNDU2OyAvL9C30LDQv9C+0LvQvdC10L3QuNC1INC80LDRgdGB0LjQstCwCiAgIH0KICAgaW50IGsseCx5LHJlc3VsdDsKICAgY2luPj5rOyAKICAgaW50IG1tYXgsbW1pbjsgLy/Qv9C10YDQtdC80LXQvdC90YvQtSDQtNC70Y8g0YXRgNCw0L3QtdC90LjRjyDQvNCw0LrRgdC40LzRg9C80LAg0Lgg0LzQuNC90LjQvNGD0LzQsCDQvdCwINC+0YLRgNC10LfQutC1CiAgIGZvcihpbnQgaT0wO2k8aztpKyspCiAgIHsKICAgICAgIGNpbiA+PiB4ID4+IHk7CiAgICAgICBtbWF4PUlOVF9NSU47CiAgICAgICBtbWluPUlOVF9NQVg7CiAgICAgICBpZih4PjApCiAgICAgICB7CiAgICAgICAgICAgZm9yKGludCBpPXgtMTtpPHk7aSsrKSAvL9C/0L7QuNGB0Log0LzQsNC60YHQuNC80YPQvNCwINC4INC80LjQvdC40LzRg9C80LAg0L3QsCDQvtGC0YDQtdC30LrQtSBbeCx5XQogICAgICAgICAgIHsKICAgICAgICAgICAgICAgaWYobW1heDxhW2ldKSBtbWF4PWFbaV07CiAgICAgICAgICAgICAgIGlmKG1taW4+YVtpXSkgbW1pbj1hW2ldOwogICAgICAgICAgIH0KICAgICAgICAgICBjb3V0IDw8IG1tYXgtbW1pbiA8PCBlbmRsOwogICAgICAgfQogICAgICAgZWxzZQogICAgICAgewogICAgICAgICAgIHgqPS0xOwogICAgICAgICAgIGFbeC0xXT15OyAvL9C30LDQvNC10L3QsCB4LdCz0L4g0Y3Qu9C10LzQtdC90YLQsCDQvdCwIHkKICAgICAgIH0KICAgfQp9