#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int l = 0; l < t; l++) {
    int n;
    cin >> n;
    cout << n;
    long long maxi = 0, mini = -1000000000, sum = 0, blue = 0;
    long long c;
    for (int i = 0; i < n; i++) {
      long long k;
      cin >> k;
      c = k;
      if (c > 0) {
        maxi = max(maxi, c);
        sum += blue;
        mini = -1000000000;
        blue = 0;
      } else {
        mini = max(mini, c);
        sum += maxi;
        maxi = 0;
        blue = mini;
      }
    }
    if (c > 0)
      cout << sum + maxi << endl;
    else {
      cout << sum + blue << endl;
    }
  }
  return 0;
}
