#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T-- > 0) {
    int n, i;
    cin >> n;
    int a[n];
    long long sum = 0;
    cin >> a[0];
    int maxi = a[0];
    for (i = 1; i < n; i++) {
      cin >> a[i];
      if ((a[i] < 0 && maxi < 0) || (a[i] > 0 && maxi > 0))
        maxi = max(maxi, a[i]);
      else {
        sum = sum + maxi;
        maxi = a[i];
      }
    }
    cout << sum + maxi << endl;
  }
}
