#include <bits/stdc++.h>
using namespace std;
typedef pair<string,string> pss;
int main(){
int t;
cin>>t;
while(t--){
int n,cnt=0;//cnt记录垃圾学生
cin>>n;
vector<pss> a(n);
set<string> b; // 记录违规出队的人
queue<string> q;
for(auto &x:a) cin>>x.first>>x.second;
for(auto x:a){
if(x.first=="in") q.push(x.second);
else{
while(!q.empty() && b.count(q.front())) q.pop(); // 先把队首已经违规的人全部 pop
if(!q.empty() && x.second==q.front()){
q.pop(); // 正常出队
}
else{
// 队列空或出队人不是队首 → 违规
b.insert(x.second);
cnt++;
}
}
}
cout<<n/2-cnt<<endl;
}
return 0;
}
using namespace std;
typedef pair<string,string> pss;
int main(){
int t;
cin>>t;
while(t--){
int n,cnt=0;//cnt记录垃圾学生
cin>>n;
vector<pss> a(n);
set<string> b; // 记录违规出队的人
queue<string> q;
for(auto &x:a) cin>>x.first>>x.second;
for(auto x:a){
if(x.first=="in") q.push(x.second);
else{
while(!q.empty() && b.count(q.front())) q.pop(); // 先把队首已经违规的人全部 pop
if(!q.empty() && x.second==q.front()){
q.pop(); // 正常出队
}
else{
// 队列空或出队人不是队首 → 违规
b.insert(x.second);
cnt++;
}
}
}
cout<<n/2-cnt<<endl;
}
return 0;
}

京公网安备 11010502036488号