#include<iostream>
#include<cstring>
#include<map>
#define int long long
using namespace std;
map<pair<int,int>,int> t;
map<int,int> nok;
int count;
int n;
int opt,k,b;
int cnt;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-')f=-1;
ch=getchar();
}
while(isdigit(ch)){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
inline void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+48);
}
signed main(){
n=read();
for(int i=1;i<=n;i++){
opt=read(),k=read(),b=read();
if(opt==1){
t[make_pair(k,b)]++;
count++;
nok[k]++;
}
if(opt==2){
write(count-nok[k]);
puts("");
}
if(opt==3){
count=nok[k];
nok.clear();
nok[k]=count;
count-=t[make_pair(k,b)];
}
}
return 0;
}