#include typedef long long ll; using namespace std; #define debug(a) cout< > mp; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); int T; scanf("%d",&T); while (T--) { mp.clear(); int n; scanf("%d",&n); for (int i = 0; i>s>>val; mp[s].push_back(val); } int res = 0; for (map >::iterator it = mp.begin(); it!=mp.end(); it++) { sort(it->second.begin(),it->second.end()); reverse(it->second.begin(),it->second.end()); // cout<second.size()<second.size()>1) res+= (it->second)[0]+(it->second)[1]; else res+=it->second[0]; // for (int i = 0; isecond.size(),2); i++) // res+=it->second[i]; } printf("%d\n",res); } return 0; }