#include <iostream>
#include <utility>
#include <algorithm>
#define SIZE 100000
using namespace std;
void build(pair<int, int>* tree, int pos, int l, int r)
{
if (l == r)
{
tree[pos].first = (l % 12345) * (l % 12345) % 12345 + ((l % 23456) * (l % 23456) % 23456) * (l % 23456) % 23456;
tree[pos].second = tree[pos].first;
}
else
{
int m = (l + r) / 2;
build(tree, pos * 2, l, m);
build(tree, pos * 2 + 1, m + 1, r);
tree[pos] = make_pair(max(tree[pos * 2].first, tree[pos * 2 + 1].first), min(tree[pos * 2].second, tree[pos * 2 + 1].second));
}
}
pair<int, int> get(pair<int, int>* tree, int pos, int l, int r, int ql, int qr)
{
if (l == ql && r == qr)
return tree[pos];
else
{
int m = (l + r) / 2;
if (qr <= m)
return get(tree, pos * 2, l, m, ql, qr);
else if (ql >= m + 1)
return get(tree, pos * 2 + 1, m + 1, r, ql, qr);
else
{
pair<int, int> a = get(tree, pos * 2, l, m, ql, m);
pair<int, int> b = get(tree, pos * 2 + 1, m + 1, r, m + 1, qr);
return make_pair(max(a.first, b.first), min(a.second, b.second));
}
}
}
void modify(pair<int, int>* tree, int pos, int l, int r, int npos, int nv)
{
if (l == r)
{
tree[pos].first = nv;
tree[pos].second = nv;
}
else
{
int m = (l + r) / 2;
if (npos <= m)
modify(tree, pos * 2, l, m, npos, nv);
else
modify(tree, pos * 2 + 1, m + 1, r, npos, nv);
tree[pos] = make_pair(max(tree[pos * 2].first, tree[pos * 2 + 1].first), min(tree[pos * 2].second, tree[pos * 2 + 1].second));
}
}
int main()
{
ios::sync_with_stdio(false);
pair<int, int> tree[SIZE * 4];
build(tree, 1, 1, SIZE);
int n, x, y;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
if (x > 0)
{
pair<int, int> query = get(tree, 1, 1, SIZE, x, y);
cout << query.first - query.second << endl;
}
else
modify(tree, 1, 1, SIZE, -x, y);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dXRpbGl0eT4KI2luY2x1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