//TOO MUCH HOMEWORK CAUSE THAT I WRITE A BAOLI
#include <bits/stdc++.h>
#define F(i,x,y) for (int i = x; i <= y; i ++ )
#define D(i,x,y) for (int i = x; i >= y; i -- )
#define E(i,s) for (auto &i : s)
#define int long long
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int N = 2e5 + 10;
#define node pair<int,int>
#define x first
#define y second
int t;
int get(node A, node B)
{
return max(A.x + B.x, A.y + B.y);
}
vector<node> l, c;
map<node, bool> mpl,mpc;
int clac()
{
int res = 1e18;
E(t,l)
if (mpl[t])
E(v,c)
if (mpc[v])
res = min(res, get(t,v));
return res == 1e18?-1:res;
}
void koishi()
{
cin >> t;
while (t -- )
{
int opt, d, a, b;
cin >> opt >> d >> a >> b;
if (opt)
{
if (d) l.push_back({a,b}), mpl[node{a,b}] = true;
else c.push_back({a,b}), mpc[node{a,b}] = true;
} else
{
if (d) mpl[node{a,b}] = false;
else mpc[node{a,b}] = false;
}
cout << clac() << '\n';
}
}
#undef int
int main()
{
ios::sync_with_stdio(NULL),cin.tie(nullptr),cout.tie(nullptr);
koishi();
return 0;
}