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