#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    long long int ans = *max_element(a, a + n);
    long long int sum = 0;
    int sign = a[0] > 0 ? -1 : 1;
    int prev = a[0];
    sum = a[0];
    for (int i = 1; i < n; i++) {
      if (a[i] * sign > 0) {
        sum += a[i];
        prev = a[i];
        sign *= -1;
      } else {
        if (a[i] > prev) {
          sum += (a[i] - prev);
          prev = a[i];
        }
      }
    }
    cout << sum << endl;
  }
}
