#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < int(n); i++) cin >> a[i];
    int flag = (a[0] < 0) ? (0) : (1), mx = a[0];
    long long int ans = 0;
    for (int i = 0; i < int(n); i++) {
      if ((a[i] > 0 && flag == 0) || a[i] < 0 && flag == 1) {
        ans += mx;
        mx = a[i];
        flag = !flag;
      } else {
        mx = max(mx, a[i]);
      }
    }
    ans += mx;
    cout << ans << "\n";
  }
}
