include <bits/stdc++.h>
using namespace std;
int main() { cin.tie(0); cout.tie(0); long long t; cin >> t; while(t--){ long long n; cin >> n; long long v [n]; long long sum; long long highestPositive; long long highestNegative; for(int i = 0; i<n; i++){ cin >> v[i]; }
if(v[0] > 0){ highestPositive = v[0]; } if(v[0] < 0){ highestNegative = v[0]; } for(int j = 1; j<n; j++){ if(v[j-1] < 0 && v[j] > 0){ sum = sum + highestNegative; highestPositive = v[j]; } if(v[j-1] > 0 && v[j] < 0){ sum = sum + highestPositive; highestNegative = v[j]; } if(v[j-1] < v[j] < 0){ highestNegative = v[j]; } if(0 < v[j-1] < v[j]){ highestPositive = v[j]; } } if(v[n-1] > 0){ sum = sum + highestPositive; } if(v[n-1] < 0){ sum = sum + highestNegative; } cout << sum << "\n"; sum = 0; }
}