#include #include #include #include #include #include #include #include #include #include #include #include #define X first #define Y second #define clr(u,v); memset(u,v,sizeof(u)); #define in() freopen("data","r",stdin); #define out() freopen("ans","w",stdout); #define Clear(Q); while (!Q.empty()) Q.pop(); #define pb push_back using namespace std; typedef long long ll; typedef pair pii; typedef pair psi; const int maxn = 1e3 + 10; const int INF = 0x3f3f3f3f; psi P[maxn]; map M; int main() { #ifdef LOCAL in(); #endif ios::sync_with_stdio(false); int T; cin>>T; while (T--) { M.clear(); int n; cin>>n; ll ans=0; for (int i=0; i>P[i].X>>P[i].Y; sort(P,P+n); for (int i=n-1; i>=0; i--) if (M[P[i].X]<2) { M[P[i].X]++; ans+=P[i].Y; } cout<