#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100];

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	m[1] = 1;
	m[2] = 2;
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
long long t[100100], cnt;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	// dbg(v);
	// dbg(v);
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		long long x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		assert(0 < m[x]);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(long long i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		assert(cnt < 4 * N);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		long long pos = query(root, 1, N) - 1;
		assert(pos >= 0);
		assert(pos < v.size());
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100], ret[300100];
long long t[100100], cnt;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());

	int nr = 0;
	for(long long i = 0; i < v.size(); i++) {

		if(m[v[i]]) continue;
		ret[nr] = v[i];
		m[v[i]] = ++nr;
		// dbg(m[x]);
		// dbg_ok;
	}

	for(long long i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		assert(m[l[i]] < N);
		assert(m[r[i]] < N);
		assert(cnt < 4 * N);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		long long pos = query(root, 1, N) - 1;
		assert(pos >= 0);
		cout << ret[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	m[1] = 1;
	m[2] = 2;
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(cnt < 1200000);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	m[1] = 1;
	m[2] = 2;
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(cnt < 1200000);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) //cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 1e18 + 10;

long long n, l, r, t;

struct nod {
	nod * l, * r;

	long long val = 0;
	int lazy = 0;
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(!node->l) node->l = new nod();
		if(!node->r) node->r = new nod();

		if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
		else node->l->lazy = 3 - node->l->lazy;

		if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
		else node->r->lazy = 3 - node->r->lazy;

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	dbg(node, l, r);
	push(node, l, r);

	if((l == 3 || l == 1)&& r == 4) {
		dbg(l, r, node->val, node->lazy, val);
	}

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);
	dbg(l,r, node->val, value(node->l, l, mid) , value(node->r, mid + 1, r));
}

long long query(nod * node, long long l, long long r) {
	dbg(node, l, r);
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;
	dbg(value(node->l, l, mid));
	if(node->l) {
		dbg(node->l->val, node->l->lazy);
	}
	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);

	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t >> l >> r;
		if(t != 3) t = 3 - t;;
		update(root, 1, N, l, r, t);
		cout << query(root, 1, N) << '\n';
	}

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
long long t[100100], cnt;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	// dbg(v);
	// dbg(v);
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		long long x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		assert(0 < m[x]);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(long long i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		long long pos = query(root, 1, N) - 1;
		assert(pos >= 0);
		assert(pos < v.size());
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) //cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 1e18 + 10;

long long n, l, r, t;

struct nod {
	nod * l, * r;

	long long val = 0, lazy = 0;

};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(!node->l) node->l = new nod();
		if(!node->r) node->r = new nod();
		if(!node->l->lazy && node->lazy == 3) node->l->lazy = node->lazy;
		else node->l->lazy = 3 - node->l->lazy;
		if(!node->r->lazy && node->lazy == 3) node->r->lazy = node->lazy;
		else node->r->lazy = 3 - node->r->lazy;

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	dbg(node, l, r);
	push(node, l, r);

	if((l == 3 || l == 1)&& r == 4) {
		dbg(l, r, node->val, node->lazy, val);
	}

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);
	dbg(l,r, node->val, value(node->l, l, mid) , value(node->r, mid + 1, r));
}

long long query(nod * node, long long l, long long r) {
	dbg(node, l, r);
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;
	dbg(value(node->l, l, mid));
	if(node->l) {
		dbg(node->l->val, node->l->lazy);
	}
	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);

	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t >> l >> r;
		if(t != 3) t = 3 - t;;
		update(root, 1, N, l, r, t);
		cout << query(root, 1, N) << '\n';
	}

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100], ret[300100];
long long t[100100], cnt;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	v.push_back(1);
	sort(v.begin(), v.end());

	int nr = 0;
	for(long long i = 0; i < v.size(); i++) {

		if(m[v[i]]) continue;
		ret[nr] = v[i];
		m[v[i]] = ++nr;
		// dbg(m[x]);
		// dbg_ok;
	}

	for(long long i = 1; i <= n; i++) {
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		long long pos = query(root, 1, N) - 1;

		cout << ret[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	// dbg(v);
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		assert(0 < m[x]);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100], ret[300100];
long long t[100100], cnt;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());

	int nr = 0;
	for(long long i = 0; i < v.size(); i++) {

		if(m[v[i]]) continue;
		ret[nr] = v[i];
		m[v[i]] = ++nr;
		// dbg(m[x]);
		// dbg_ok;
	}

	for(long long i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		assert(m[l[i]] < N);
		assert(m[r[i]] < N);
		assert(cnt < 4 * N);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		long long pos = query(root, 1, N) - 1;
		assert(pos >= 0);

		if(ret[pos] == 15039850410053) {
			cout << pos << ' ' << root->val <<  '\n';
			cout << v[0] << ' ' << v[1] << '\n';
			cout << ret[0] << ' ' << ret[1] << '\n';
			return 0;
		}

		cout << ret[pos] << '\n';
	}
	dbg(cnt);

}


#pragma pack(1)
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) //cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 1e18 + 10;

long long n, l, r, t;

struct nod {
	nod * l, * r;

	long long val = 0;
	char lazy = 0;
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	dbg(node, l, r);
	push(node, l, r);

	if((l == 3 || l == 1)&& r == 4) {
		dbg(l, r, node->val, node->lazy, val);
	}

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);
	dbg(l,r, node->val, value(node->l, l, mid) , value(node->r, mid + 1, r));
}

long long query(nod * node, long long l, long long r) {
	dbg(node, l, r);
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;
	dbg(value(node->l, l, mid));
	if(node->l) {
		dbg(node->l->val, node->l->lazy);
	}
	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t >> l >> r;
		if(t != 3) t = 3 - t;;
		update(root, 1, N, l, r, t);
		cout << query(root, 1, N) << '\n';
	}

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	//dbg(v);
	// dbg(v);
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	//dbg(v);
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		long long x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		assert(0 < m[x]);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	m[1] = 1;
	m[2] = 2;
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(cnt < 1200000);
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!" << endl

const long long N = 3e5 + 10;

long long n, l[100100], r[100100];
int t[100100], cnt;

struct nod {
	nod * l, * r;

	int val = 0;
	char lazy = 0;

	nod() {
		l = r = 0;
		cnt++;
	}
};

long long value(nod * node, long long l, long long r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, long long l, long long r) {
	if(node->lazy) {
		if(l != r) {
			if(!node->l) node->l = new nod();
			if(!node->r) node->r = new nod();

			if(!node->l->lazy || node->lazy != 3) node->l->lazy = node->lazy;
			else node->l->lazy = 3 - node->l->lazy;

			if(!node->r->lazy || node->lazy != 3) node->r->lazy = node->lazy;
			else node->r->lazy = 3 - node->r->lazy;
		}

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, long long l, long long r, long long x, long long y, long long val) {
	push(node, l, r);

	if(x <= l && r <= y)
		return void(node->lazy = val);

	long long mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);

}
vector <long long> v;
map <long long, long long> m;

long long query(nod * node, long long l, long long r) {
	push(node, l, r);
	if(l == r) return l;

	long long mid = (l + r) / 2;

	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);
	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> t[i] >> l[i] >> r[i];
		if(t[i] != 3) t[i] = 3 - t[i];
		v.push_back(l[i]);
		v.push_back(r[i]);
		v.push_back(r[i] + 1);
	}

	// dbg(v);
	sort(v.begin(), v.end());
	v.resize(distance(v.begin(), unique(v.begin(), v.end())));
	// dbg(v);
	// dbg_ok;
	// dbg(m[1]);

	for(long long i = 0; i < v.size(); i++) {
		// dbg(v[i], i, m[v[i]]);
		int x = v[i];
		m[x] = i + 1;
		assert(m[x] < N);
		// dbg(m[x]);
		// dbg_ok;
	}

	for(int i = 1; i <= n; i++) {
		assert(m[l[i]] != 0);
		assert(m[r[i]] != 0);
		// dbg(l[i], r[i], t[i]);
		update(root, 1, N, m[l[i]], m[r[i]], t[i]);
		// dbg(m[l[i]], m[r[i]], t[i]);
		int pos = query(root, 1, N) - 1;
		// dbg(pos);
		cout << v[pos] << '\n';
	}
	dbg(cnt);

}


#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) //cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 100100;

int n, l, r, t;

struct nod {
	nod * l, * r;

	int val = 0, lazy = 0;

};

int value(nod * node, int l, int r) {
	if(node == 0) return 0;
	if(node->lazy == 0)
		return node->val;
	if(node->lazy < 3)
		return (node->lazy - 1) * (r - l + 1);
	return (r - l + 1) - node->val;
}

void push(nod * node, int l, int r) {
	if(node->lazy) {
		if(!node->l) node->l = new nod();
		if(!node->r) node->r = new nod();
		if(!node->l->lazy) node->l->lazy = node->lazy;
		else node->l->lazy = 3 - node->l->lazy;
		if(!node->r->lazy) node->r->lazy = node->lazy;
		else node->r->lazy = 3 - node->r->lazy;

		if(node->lazy != 3) node->val = (node->lazy - 1) * (r - l  + 1);
		else node->val = (r - l + 1) - node->val;
		node->lazy = 0;
	}
}

void update(nod * node, int l, int r, int x, int y, int val) {
	dbg(node, l, r);
	push(node, l, r);

	if((l == 3 || l == 1)&& r == 4) {
		dbg(l, r, node->val, node->lazy, val);
	}

	if(x <= l && r <= y)
		return void(node->lazy = val);

	int mid = (l + r) / 2;
	if(x <= mid) {
		if(!node->l) node->l = new nod();
		update(node->l, l, mid, x, y, val);
	}
	if(y > mid) {
		if(!node->r) node->r = new nod();
		update(node->r, mid + 1, r, x, y, val);
	}

	node->val = value(node->l, l, mid) + value(node->r, mid + 1, r);
	dbg(l,r, node->val, value(node->l, l, mid) , value(node->r, mid + 1, r));
}

int query(nod * node, int l, int r) {
	dbg(node, l, r);
	push(node, l, r);
	if(l == r) return l;

	int mid = (l + r) / 2;
	dbg(value(node->l, l, mid));
	if(node->l) {
		dbg(node->l->val, node->l->lazy);
	}
	if(value(node->l, l, mid) < (mid - l + 1)) {
		if(!node->l) return l;
		return query(node->l, l, mid);
	}
	if(!node->r) return mid + 1;
	return query(node->r, mid + 1, r);
}

int main() {
	ios_base::sync_with_stdio(false);

	nod * root =new nod();
	// update(root, 1, N, 3, 4, 2);
	// update(root, 1, N, 1, 6, 3);
	// cout << query(root, 1, N);

	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> t >> l >> r;
		if(t != 3) t = 3 - t;;
		update(root, 1, N, l, r, t);
		cout << query(root, 1, N) << '\n';
	}

}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
      cor.push_back(i);
    if(s[i]==')')
      paren.push_back(i);
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(s[i]=='(' && !auxiliar)
    {
      if(paren[paren.size()]<=i)
      {
        auxiliar=true;
      }
      if(!auxiliar)
      {
      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }
      }
    }
    else if(s[i]=='[')
    {
      if(cor[cor.size()]<=i)
      {
        aux=true;
      }
      if(!aux)
      {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor++;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen++;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(!paren.empty())
    {
    if(s[i]=='(' && paren[lastparen-1]!=0)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
          else if(paren[(j+paren.size()-1)/2]<i)
            j=(j+paren.size()-1)/2;
      }

    }
    }
    if(!cor.empty())
    {
    if(s[i]=='[' && cor[lastcor-1]!=0)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
          else if(cor[(j+cor.size()-1)/2]<i)
            j=(j+cor.size()-1)/2;
      }
    }
    }
  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor=i;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen=i;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(s[i]=='(' && i<lastparen)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }

    }
    else if(s[i]=='[' && i<lastcor)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor++;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen++;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(!paren.empty())
    {
    if(s[i]=='(' && paren[lastparen-1]!=0)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }

    }
    }
    if(!cor.empty())
    {
    if(s[i]=='[' && cor[lastcor-1]!=0)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
    }
    }
  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
#define MAX 10007
using namespace std;
typedef unsigned long long int ulli;
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    string  s;
    cin>>s;
    int firstcor=0;
    int firstparen=0;
    int cont=0;
    for(int i=0; i<s.size(); ++i)
    {
      if(s[i]=='(')
      firstparen++;
      else if(s[i]=='[')
      firstcor++;
      if(s[i]==')')
      {
        if(firstparen)
        {
          cont++;
          firstparen--;
        }
      }
      if(s[i]==']')
      {
        if(firstcor)
        {
          cont++;
          firstcor--;
        }
      }
    }
    cout<<cont <<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
#define MAX 10007
using namespace std;
typedef unsigned long long int ulli;
int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--)
  {
    string  s;
    cin>>s;
    int firstcor=0;
    int firstparen=0;
    int cont=0;
    for(int i=0; i<s.size(); ++i)
    {
      if(s[i]=='(')
      firstparen++;
      else if(s[i]=='[')
      firstcor++;
      if(s[i]==')')
      {
        if(firstparen)
        {
          cont++;
          firstparen--;
        }
      }
      if(s[i]==']')
      {
        if(firstcor)
        {
          cont++;
          firstcor--;
        }
      }
    }
    cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor++;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen++;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(s[i]=='(' && paren[lastparen]!=0)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }

    }
    else if(s[i]=='[' && cor[lastcor]!=0)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor++;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen++;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(!paren.empty())
    {
    if(s[i]=='(' && paren[lastparen-1]!=0)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
          else if(paren[(j+paren.size()-1)/2]<i)
            j=(j+paren.size()-1)/2;
      }

    }
    }
    else
    aux=true;
    if(!cor.empty())
    {
    if(s[i]=='[' && cor[lastcor-1]!=0)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
          else if(cor[(j+cor.size()-1)/2]<i)
            j=(j+cor.size()-1)/2;
      }
    }
    }
    else
    auxiliar=true;
  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0;

  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]=='(')
    {
      for(int j=i+1; j<s.size(); ++j)
      {
        if(s[j]==')')
        {
          cont++;
          s[i]='1';
          s[j]='1';
          break;
        }
      }
    }
    else if(s[i]=='[')
    {
      for(int j=i+1; j<s.size(); ++j)
      {
        if(s[j]==']')
        {
          cont++;
          s[i]='1';
          s[j]='1';
          break;
        }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0,lastcor=0, lastparen=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
    {
      lastcor++;
      cor.push_back(i);
    }
    if(s[i]==')')
    {
      lastparen++;
      paren.push_back(i);
    }
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(s[i]=='(' && paren[lastparen-1]!=0)
    {

      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }

    }
    else if(s[i]=='[' && cor[lastcor-1]!=0)
    {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ENDL '\n'
using namespace std;
typedef unsigned long long int ulli;

int main()
{
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin>>t;
  while(t--){
  string s;
  cin>>s;
  int cont=0;
  vector<int>cor, paren;
  for(int i=0; i<s.size(); ++i)
  {
    if(s[i]==']')
      cor.push_back(i);
    if(s[i]==')')
      paren.push_back(i);
  }
  bool aux=false, auxiliar=false;
  for(int i=0; i<s.size(); ++i)
  {
    if(aux && auxiliar)
    break;
    if(s[i]=='(' && !auxiliar)
    {
      if(paren[paren.size()-1]<=i)
      {
        auxiliar=true;
      }
      if(!auxiliar)
      {
      for(int j=0; j<paren.size(); ++j)
      {
          if(paren[j]>i)
          {
            cont++;
            paren[j]=0;
            break;
          }
      }
      }
    }
    else if(s[i]=='[')
    {
      if(cor[cor.size()-1]<=i)
      {
        aux=true;
      }
      if(!aux)
      {
      for(int j=0; j<cor.size(); ++j)
      {
          if(cor[j]>i)
          {
            cont++;
            cor[j]=0;
            break;
          }
      }
      }
    }

  }

  cout<<cont<<ENDL;
  }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    char ch =cin.get();
    while(t--){
        string x;
        getline(cin,x);
        // cin>>x;
        int  m = x.size();
        // cout<<m<<endl;
        int  count =0;
        for(int  i=0;i<m;i++){
            if(x[i]=='['){
                for(int  j=i+1;j<m;j++){
                    if(x[j]==']' ){
                        count++;
                        x[j]='0';
                    }
                }
            }
           else  if(x[i]=='('){
                for(int  j=i+1;j<m;j++){
                    if(x[j]==')' ){
                        count++;
                        x[j]='0';
                    }
                }
            }
            else continue;
        }
        cout<<count<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    char ch =cin.get();
    while(t--){
        string x;
        getline(cin,x);
        // cin>>x;
        int  m = x.size();
        // cout<<m<<endl;
        int  count =0;
        for(int  i=0;i<m;i++){
            if(x[i]=='[' || x[i]=='('){
                for(int  j=i+1;j<m;j++){
                    if(x[j]==']' ||x[j]==')'){
                        count++;
                        x[j]='0';
                    }
                }
            }
            // else continue;
        }
        cout<<count<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    char ch =cin.get();
    while(t--){
        string s;
        getline(cin,s);
        // cin>>x;
        int  m = s.size();
        // cout<<m<<endl;
        int  ans=0,b1=0,b2=0;
        for(int  i=0;i<m;i++){

              if (s[i] == '(') b1++;
            if (s[i] == '[') b2++;
            if (s[i] == ')' && b1 > 0) {
                ans++;
                b1--;
            }
            if (s[i] == ']' && b2 > 0) {
                ans++;
                b2--;
            }
        }
        cout << ans << "\n";

    }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    char ch =cin.get();
    while(t--){
        string x;
        getline(cin,x,'\n');
        // cin>>x;
        ll m = x.size();
        // cout<<m<<endl;
        ll count =0;
        for(ll i=0;i<m;i++){
            if(x[i]=='[' || x[i]=='('){
                for(ll j=i+1;j<m;j++){
                    if(x[j]==']' ||x[j]==')'){
                        count++;
                        x[j]='0';
                    }
                }
            }
            // else continue;
        }
        cout<<count<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    while(t--){
        string x;
        // getline(cin,x);
        cin>>x;
        int m = x.size();
        // cout<<m<<endl;
        int count =0;
        for(int i=0;i<m;i++){
            if(x[i]=='[' || x[i]=='('){
                for(int j=i+1;j<m;j++){
                    if(x[j]==']' ||x[j]==')'){
                        count++;
                        x[j]='0';
                    }
                }
            }
            // else continue;
        }
        cout<<count<<endl;

    }
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
    int t=1;
    cin>>t;
    while(t--){
        string x;
        // getline(cin,x);
        cin>>x;
        ll m = x.size();
        // cout<<m<<endl;
        ll count =0;
        for(ll i=0;i<m;i++){
            if(x[i]=='[' || x[i]=='('){
                for(ll j=i+1;j<m;j++){
                    if(x[j]==']' ||x[j]==')'){
                        count++;
                        x[j]='0';
                    }
                }
            }
            // else continue;
        }
        cout<<count<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;cin>>t;
	while(t--)
	{
		string s;cin>>s;
		int a=0,b=0,c=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='(')
			a++;
			else if(s[i]=='[')
			b++;
			else if(s[i]==')')
			{
				if(a)c++,a--;
			}
			else
			{
				if(b)c++;b--;
			}
		}
		cout<<c<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;cin>>t;
	while(t--)
	{
		string s;cin>>s;
		int a=0,b=0,c=0;
		for(int i=0;i<s.size();i++)
		{
			if(s[i]=='(')
			a++;
			else if(s[i]=='[')
			b++;
			else if(s[i]==')'&&a)
			{
				c++,a--;
			}
			else if(s[i]=']'&&b)
			{
				c++;b--;
			}
		}
		cout<<c<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int t;cin>>t;
	while(t--)
	{
	   string s;cin>>s;
	   int a=0,b=0,c=0,d=0;
	   for(int i=0;i<s.size();i++)
	   {
		  if(s[i]=='[')
		  	a++;
		  if(s[i]==']'){
		  	if(a==1)
		  b++;
		  else
		  a++;
		  a--;}
		  if(s[i]=='(')
		  c++;
		  if(s[i]==')')
		  {
		  	if(c==1)
		  	d++;
		  	else
		  	c++;
		     c--;
		  }
	   }
	   cout<<b+d<<"\n";
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  string s;
  while (t--) {
    cin >> s;
    int f = 0, t = 0;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '(') f++;
      else if (s[i] == ')' && f) f--, ans++;
      else if (s[i] == ']' && t) t--, ans++;
      else if (s[i] == '[') t++;
    }
    cout << ans << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long a[100005],b,c,d,e,f,n,m,k,l,p,i,j,mi,ma;
string s;

int main()
{
    cin>>l;
    while(l--)
    {
        c=0;
        cin>>s;
        for(i=0; i<s.size(); i++)
            if(s[i]=='(')for(j=i; j<s.size(); j++)if(s[j]==')')c++;
        for(i=0; i<s.size(); i++)
            if(s[i]=='[')for(j=i; j<s.size(); j++)if(s[j]==']')c++;
        cout<<c<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long a[100005],b,c,d,e,f,n,m,k,l,p,i,j,mi,ma;
string s;

int main()
{
    cin>>l;
    while(l--)
    {
        c=0;
        cin>>s;
        for(i=0; i<s.size(); i++)
            if(s[i]=='(')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==')')
                    {
                        e++;
                        c++;
                    }
            }
        for(i=0; i<s.size(); i++)
            if(s[i]=='[')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==']')
                    {
                        e++;
                        c++;
                    }
            }
        cout<<min(e,min(d,c))<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long a[100005],b,c,d,e,f,n,m,k,l,p,i,j,mi,ma;
string s;

int main()
{
    cin>>l;
    while(l--)
    {
        c=0;
        e=0;
        d=0;
        cin>>s;
        for(i=0; i<s.size(); i++)
            if(s[i]=='(')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==')')
                    {
                        e++;
                        c++;
                    }
            }
        for(i=0; i<s.size(); i++)
            if(s[i]=='[')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==']')
                    {
                        e++;
                        c++;
                    }
            }
        cout<<min(e,min(d,c))<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long a[100005],b,c,d,e,f,n,m,k,l,p,i,j,mi,ma;
string s;

int main()
{
    cin>>l;
    while(l--)
    {
        c=0;
        cin>>s;
        for(i=0; i<s.size(); i++)
            if(s[i]=='(')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==')')
                    {
                        e++;
                        c++;
                    }
            }
        for(i=0; i<s.size(); i++)
            if(s[i]=='[')
            {
                d++;
                for(j=i; j<s.size(); j++)if(s[j]==']')
                    {
                        e++;
                        c++;
                    }
            }
        cout<<c<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define st first
#define nd second
#define ii pair<int,int>
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
const int MaxN = 220;
const int MX=1e3;
using namespace std;
unsigned ll factorial(unsigned ll n)
{

    if (n == 0)
        return 1;
    return (n * factorial(n - 1));
}
string decimal_to_binary(int x){
    string ans = "";
    while(x > 0){
        if(x & 1)
            ans += "1";
        else
            ans += "0";
        x = x >> 1;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
bool isPrime(int x){
    for(int i=2 ; i*i <= x ; ++i)
        if(x % i == 0) return false;
    return true;
}
int arr[1000];
int sum(int a,int b){
    int s=0;
    for(int i=a; i<=b ; i++){
        s+=arr[i];
    }
    return s;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
void g(int a){
    cout<<a<<" "<<2*a<<endl;
}
ll c(ll x, ll r ){
    ll h=factorial(x)/(factorial(r)*factorial(x-r));
    return h;
}
ll ss(ll s , ll p){
    ll an=1;
    rep(i,p){
        an*=s;
    }
    return an;
}
int main(){
    //cout <<setprecision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("bugged.in", "r", stdin);
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        vector<int> A;
        vector<int> B;
        vector<int> C;
        vector<int> D;
        for(int i=0 ; i<s.size() ; i++){
            if(s[i]=='('){
                A.push_back(i);
            }
            else if(s[i]==')'){
                B.push_back(i);
            }
            else if(s[i]=='['){
                C.push_back(i);
            }
            else if(s[i]==']'){
                D.push_back(i);
            }
        }
        ll ans=0;
        ll l=0;
        //ll x=max(A.size(),B.size());
        for(int i=0 ; i<B.size(); i++){
            if(A[l]<B[i]){
                ans++;
                l++;
            }
        }
        ll k=0;
        //ll m=max(D.size(),C.size());
        for(int i=0 ; i<D.size() ; i++){
            if(C[k]<D[i]){
                ans++;
                k++;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define st first
#define nd second
#define ii pair<int,int>
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
const int MaxN = 220;
const int MX=1e3;
using namespace std;
unsigned ll factorial(unsigned ll n)
{

    if (n == 0)
        return 1;
    return (n * factorial(n - 1));
}
string decimal_to_binary(int x){
    string ans = "";
    while(x > 0){
        if(x & 1)
            ans += "1";
        else
            ans += "0";
        x = x >> 1;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
bool isPrime(int x){
    for(int i=2 ; i*i <= x ; ++i)
        if(x % i == 0) return false;
    return true;
}
int arr[1000];
int sum(int a,int b){
    int s=0;
    for(int i=a; i<=b ; i++){
        s+=arr[i];
    }
    return s;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
void g(int a){
    cout<<a<<" "<<2*a<<endl;
}
ll c(ll x, ll r ){
    ll h=factorial(x)/(factorial(r)*factorial(x-r));
    return h;
}
ll ss(ll s , ll p){
    ll an=1;
    rep(i,p){
        an*=s;
    }
    return an;
}
int main(){
    //cout <<setprecision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("bugged.in", "r", stdin);
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        vector<int> A;
        vector<int> B;
        vector<int> C;
        vector<int> D;
        for(int i=0 ; i<s.size() ; i++){
            if(s[i]=='('){
                A.push_back(i);
            }
            else if(s[i]==')'){
                B.push_back(i);
            }
            else if(s[i]=='['){
                C.push_back(i);
            }
            else{
                D.push_back(i);
            }
        }
        ll ans=0;
        ll x=min(A.size(),B.size());
        for(int i=0 ; i<x ; i++){
            if(A[i]<B[i]){
                ans++;
            }
        }
        ll m=min(D.size(),C.size());
        for(int i=0 ; i<m ; i++){
            if(C[i]<D[i]){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define st first
#define nd second
#define ii pair<int,int>
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
const int MaxN = 220;
const int MX=1e3;
using namespace std;
unsigned ll factorial(unsigned ll n)
{

    if (n == 0)
        return 1;
    return (n * factorial(n - 1));
}
string decimal_to_binary(int x){
    string ans = "";
    while(x > 0){
        if(x & 1)
            ans += "1";
        else
            ans += "0";
        x = x >> 1;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
bool isPrime(int x){
    for(int i=2 ; i*i <= x ; ++i)
        if(x % i == 0) return false;
    return true;
}
int arr[1000];
int sum(int a,int b){
    int s=0;
    for(int i=a; i<=b ; i++){
        s+=arr[i];
    }
    return s;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
void g(int a){
    cout<<a<<" "<<2*a<<endl;
}
ll c(ll x, ll r ){
    ll h=factorial(x)/(factorial(r)*factorial(x-r));
    return h;
}
ll ss(ll s , ll p){
    ll an=1;
    rep(i,p){
        an*=s;
    }
    return an;
}
int main(){
    //cout <<setprecision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("bugged.in", "r", stdin);
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        vector<int> A;
        vector<int> B;
        vector<int> C;
        vector<int> D;
        for(int i=0 ; i<s.size() ; i++){
            if(s[i]=='('){
                A.push_back(i);
            }
            else if(s[i]==')'){
                B.push_back(i);
            }
            else if(s[i]=='['){
                C.push_back(i);
            }
            else{
                D.push_back(i);
            }
        }
        ll ans=0;
        ll x=max(A.size(),B.size());
        for(int i=0 ; i<x ; i++){
            if(A[i]<B[i]){
                ans++;
            }
        }
        ll m=max(D.size(),C.size());
        for(int i=0 ; i<m ; i++){
            if(C[i]<D[i]){
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define st first
#define nd second
#define ii pair<int,int>
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
const int MaxN = 220;
const int MX=1e3;
using namespace std;
unsigned ll factorial(unsigned ll n)
{

    if (n == 0)
        return 1;
    return (n * factorial(n - 1));
}
string decimal_to_binary(int x){
    string ans = "";
    while(x > 0){
        if(x & 1)
            ans += "1";
        else
            ans += "0";
        x = x >> 1;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
bool isPrime(int x){
    for(int i=2 ; i*i <= x ; ++i)
        if(x % i == 0) return false;
    return true;
}
int arr[1000];
int sum(int a,int b){
    int s=0;
    for(int i=a; i<=b ; i++){
        s+=arr[i];
    }
    return s;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
void g(int a){
    cout<<a<<" "<<2*a<<endl;
}
ll c(ll x, ll r ){
    ll h=factorial(x)/(factorial(r)*factorial(x-r));
    return h;
}
ll ss(ll s , ll p){
    ll an=1;
    rep(i,p){
        an*=s;
    }
    return an;
}
int main(){
    //cout <<setprecision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("bugged.in", "r", stdin);
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        vector<int> A;
        vector<int> B;
        vector<int> C;
        vector<int> D;
        for(int i=0 ; i<s.size() ; i++){
            if(s[i]=='('){
                A.push_back(i);
            }
            else if(s[i]==')'){
                B.push_back(i);
            }
            else if(s[i]=='['){
                C.push_back(i);
            }
            else if(s[i]==']'){
                D.push_back(i);
            }
        }
        ll ans=0;
        ll l=0;
        //ll x=max(A.size(),B.size());
        for(int i=0 ; i<B.size(); i++){
            if(l==A.size()){
                break;
            }
            if(A[l]<B[i]){
                ans++;
                l++;
            }

        }
        ll k=0;
        //ll m=max(D.size(),C.size());
        for(int i=0 ; i<D.size() ; i++){
            if(k==C.size()){
                break;
            }
            if(C[k]<D[i]){
                ans++;
                k++;
            }

        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define st first
#define nd second
#define ii pair<int,int>
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
const int MaxN = 220;
const int MX=1e3;
using namespace std;
unsigned ll factorial(unsigned ll n)
{

    if (n == 0)
        return 1;
    return (n * factorial(n - 1));
}
string decimal_to_binary(int x){
    string ans = "";
    while(x > 0){
        if(x & 1)
            ans += "1";
        else
            ans += "0";
        x = x >> 1;
    }
    reverse(ans.begin(),ans.end());
    return ans;
}
bool isPrime(int x){
    for(int i=2 ; i*i <= x ; ++i)
        if(x % i == 0) return false;
    return true;
}
int arr[1000];
int sum(int a,int b){
    int s=0;
    for(int i=a; i<=b ; i++){
        s+=arr[i];
    }
    return s;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}
void g(int a){
    cout<<a<<" "<<2*a<<endl;
}
ll c(ll x, ll r ){
    ll h=factorial(x)/(factorial(r)*factorial(x-r));
    return h;
}
ll ss(ll s , ll p){
    ll an=1;
    rep(i,p){
        an*=s;
    }
    return an;
}
int main(){
    //cout <<setprecision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("bugged.in", "r", stdin);
    int t;
    cin>>t;
    while(t--) {
        string s;
        cin>>s;
        vector<int> A;
        vector<int> B;
        vector<int> C;
        vector<int> D;
        for(int i=0 ; i<s.size() ; i++){
            if(s[i]=='('){
                A.push_back(i);
            }
            else if(s[i]==')'){
                B.push_back(i);
            }
            else if(s[i]=='['){
                C.push_back(i);
            }
            else if(s[i]==']'){
                D.push_back(i);
            }
        }
        ll ans=0;
        ll l=0;
        //ll x=max(A.size(),B.size());
        for(int i=0 ; i<B.size(); i++){
            if(A[l]<B[i]){
                ans++;
                l++;
            }
            if(l==A.size()){
                break;
            }
        }
        ll k=0;
        //ll m=max(D.size(),C.size());
        for(int i=0 ; i<D.size() ; i++){
            if(C[k]<D[i]){
                ans++;
                k++;
            }
            if(k==C.size()){
                break;
            }
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define pb push_back
#define F first
#define S second
#define rast(a,b,c,d) sqrt(pow(a-b,2)+pow(c-d,2))
#define outzn(x) cout<<setprecision(x)<<fixed
typedef double dob;
typedef long long ll;
const int INF = 1e9+7;

int t;

int main()
{
  iostream::sync_with_stdio(0); cin.tie(0);
  ios_base::sync_with_stdio(0); cout.tie(0);
  cin>>t;
  while (t--)
  {
    string s;
    ll ans=0;
    int knz1=0,knz2=0;
    cin>>s;
    int d=s.length()-1;
    if (s[0]=='(') knz1++;
    if (s[0]=='[') knz2++;
    for (int i=1; i<=d; i++)
    {
        if (s[i]=='(') knz1++;
        if (s[i]=='[') knz2++;
        if (s[i]==')' && knz1>0) {knz1--; ans++;}
        if (s[i]==']' && knz2>0) {knz2--; ans++;}
    }
    cout<<ans<<"\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define pb push_back
#define F first
#define S second
#define rast(a,b,c,d) sqrt(pow(a-b,2)+pow(c-d,2))
#define outzn(x) cout<<setprecision(x)<<fixed
typedef double dob;
typedef long long ll;
const int INF = 1e9+7;

int t;

int main()
{
  cin>>t;
  while (t--)
  {
    string s;
    int knz1[100001]={},knz2[100001]={},kz1[100001]={},kz2[100001]={};
    cin>>s;
    int d=s.length()-1;
    for (int i=0; i<=d; i++)
    {
      if (i!=0)
      {
        knz1[i]=knz1[i-1];
        knz2[i]=knz2[i-1];
        kz1[i]=kz1[i-1];
        kz2[i]=kz2[i-1];
      }
      if (s[i]=='(') knz1[i]++;
      if (s[i]=='[') knz2[i]++;
      if (s[i]==')' && knz1[i]>0) {knz1[i]--; kz1[i]++;}
      if (s[i]==']' && knz2[i]>0) {knz2[i]--; kz2[i]++;}
    }
    cout<<kz1[d]+kz2[d]<<"\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define pb push_back
#define F first
#define S second
#define rast(a,b,c,d) sqrt(pow(a-b,2)+pow(c-d,2))
#define outzn(x) cout<<setprecision(x)<<fixed
typedef double dob;
typedef long long ll;
const int INF = 1e9+7;

int t;

int main()
{
  cin>>t;
  while (t--)
  {
    string s;
    ll knz1[100001]={},knz2[100001]={},kz1[100001]={},kz2[100001]={};
    cin>>s;
    int d=s.length()-1;
    for (int i=0; i<=d; i++)
    {
      if (i!=0)
      {
        knz1[i]=knz1[i-1];
        knz2[i]=knz2[i-1];
        kz1[i]=kz1[i-1];
        kz2[i]=kz2[i-1];
      }
      if (s[i]=='(') knz1[i]++;
      if (s[i]=='[') knz2[i]++;
      if (s[i]==')' && knz1[i]>0) {knz1[i]--; kz1[i]++;}
      if (s[i]==']' && knz2[i]>0) {knz2[i]--; kz2[i]++;}
    }
    cout<<kz1[d]+kz2[d]<<"\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define pb push_back
#define F first
#define S second
#define rast(a,b,c,d) sqrt(pow(a-b,2)+pow(c-d,2))
#define outzn(x) cout<<setprecision(x)<<fixed
typedef double dob;
typedef long long ll;
const int INF = 1e9+7;

int t;

int main()
{
  cin>>t;
  while (t--)
  {
    string s;
    int knz1[100001]={},knz2[100001]={},kz1[100001]={},kz2[100001]={};
    cin>>s;
    int d=s.length()-1;
    if (s[0]=='(') knz1[0]++;
    if (s[0]=='[') knz2[0]++;
    for (int i=1; i<=d; i++)
    {
        knz1[i]=knz1[i-1];
        knz2[i]=knz2[i-1];
        kz1[i]=kz1[i-1];
        kz2[i]=kz2[i-1];
      if (s[i]=='(') knz1[i]++;
      if (s[i]=='[') knz2[i]++;
      if (s[i]==')' && knz1[i]>0) {knz1[i]--; kz1[i]++;}
      if (s[i]==']' && knz2[i]>0) {knz2[i]--; kz2[i]++;}
    }
    cout<<kz1[d]+kz2[d]<<"\n";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define pb push_back
#define F first
#define S second
#define rast(a,b,c,d) sqrt(pow(a-b,2)+pow(c-d,2))
#define outzn(x) cout<<setprecision(x)<<fixed
typedef double dob;
typedef long long ll;
const int INF = 1e9+7;

int t;

int main()
{
  iostream::sync_with_stdio(0); cin.tie(0);
  ios_base::sync_with_stdio(0); cout.tie(0);
  cin>>t;
  while (t--)
  {
    string s;
    ll ans=0;
    int knz1[100001]={},knz2[100001]={};
    cin>>s;
    int d=s.length()-1;
    if (s[0]=='(') knz1[0]++;
    if (s[0]=='[') knz2[0]++;
    for (int i=1; i<=d; i++)
    {
        knz1[i]=knz1[i-1];
        knz2[i]=knz2[i-1];
        if (s[i]=='(') knz1[i]++;
        if (s[i]=='[') knz2[i]++;
        if (s[i]==')' && knz1[i]>0) {knz1[i]--; ans++;}
        if (s[i]==']' && knz2[i]>0) {knz2[i]--; ans++;}
    }
    cout<<ans<<"\n";
  }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      string a;
      cin >> a;
      long n = a.size(), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
            continue;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
               continue;
            }
         }

         if(a[i] == '[')
         {
            c2++;
            continue;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
               continue;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      char a[20002];
      cin >> a;
      long n = a.size(), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
            }
         }

         if(a[i] == '[')
         {
            c2++;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      char a[100000];
      cin >> a;
      long n = strlen(a), c1 =0, c2=0, ans=0;
      for(int i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
            }
         }

         if(a[i] == '[')
         {
            c2++;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      char a[20002];
      cin >> a;
      long n = strlen(a), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
            }
         }

         if(a[i] == '[')
         {
            c2++;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include<iostream>
#include<string.h>
#define iamspeed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      char a[20002];
      cin >> a;
      long n = strlen(a), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
            continue;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
               continue;
            }
         }

         if(a[i] == '[')
         {
            c2++;
            continue;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
               continue;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      char a[20002];
      cin >> a;
      long n = strlen(a), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
            continue;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
               continue;
            }
         }

         if(a[i] == '[')
         {
            c2++;
            continue;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
               continue;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#define iamspeed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
using namespace std;

int main()
{
   int t;
   cin >> t;
   while(t--)
   {
      string a;
      cin >> a;
      long n = a.size(), c1 =0, c2=0, ans=0;
      for(long i=0; i<n;i++)
      {
         if(a[i] == '(')
         {
            c1++;
            continue;
         }
         else if(a[i] == ')')
         {
            if(c1 > 0)
            {
               c1--;
               ans++;
               continue;
            }
         }

         if(a[i] == '[')
         {
            c2++;
            continue;
         }
         else if(a[i] == ']')
         {
            if(c2 > 0)
            {
               c2--;
               ans++;
               continue;
            }
         }
      }
      cout << ans << "\n";
   }
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	IOS
	int t;
	cin >> t;
	while(t--)
	{
	    string s;
	    cin >> s;
	    int count = 0;
	    for(int i = 0;i < s.length();++i)
	    {
	        if(s[i] == '(')
	        for(int j = i;j < s.length();++j)
	        {
	            if(s[j] == ')')
	            {
	                count ++;
	                break;
	            }
	        }
	        else if(s[i] == '[')
	        for(int j = s.length() -1;j >= i;--j)
	        {
	            if(s[j] == ']')
	            {
	                count++;
	                break;
	            }
	        }
	        else
	        continue;
	    }
	    cout << count << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	IOS
	int t;
	cin >> t;
	while(t--)
	{
	    string s;
	    cin >> s;
	    int count = 0;
	    for(int i = 0;i < s.length();++i)
	    {
	        if(s[i] == '(')
	        for(int j = i+1;j < s.length();++j)
	        {
	            if(s[j] == ')')
	            {
	                count ++;
	                break;
	            }
	        }
	        else if(s[i] == '[')
	        for(int j = i+1;j < s.length();++j)
	        {
	            if(s[j] == ']')
	            {
	                count++;
	                break;
	            }
	        }
	        else
	        continue;
	    }
	    cout << count << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main() {
	IOS
	int t;
	cin >> t;
	while(t--)
	{
	    string s;
	    cin >> s;
	    int count = 0;
	    for(int i = 0;i < s.length() - 1;++i)
	    {
	        if(s[i] == '(')
	        for(int j = i+1;j < s.length();++j)
	        {
	            if(s[j] == ')')
	            {
	                count ++;
	                break;
	            }
	        }
	        else if(s[i] == '[')
	        for(int j = i+1;j < s.length();++j)
	        {
	            if(s[j] == ']')
	            {
	                count++;
	                break;
	            }
	        }
	        else
	        continue;
	    }
	    cout << count << endl;
	}
	return 0;
}