#include<bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long ll;
ll t;
ll x;
int main(){
ios::sync_with_stdio(0);
cin>>t;
while(t--){
vector<ll> vec;
ll sz=0;
while(1){
cin>>x;
if(!x)break;
if(x!=-1){
sz++;
ll p=lower_bound(vec.begin(),vec.end(),x)-vec.begin();
vec.insert(vec.begin()+p,x);
}
else{
cout<<vec[(sz+1)/2-1]<<'\n';
vec.erase(vec.begin()+(sz+1)/2-1);
sz--;
}
}
}
return 0;
}
感觉复杂度正确(