#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) {
  if (x > y)
    return x;
  else
    return y;
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  long long n, numberlist[200002];
  while (t--) {
    cin >> n;
    for (long long i = 0; i < n; i++) {
      cin >> numberlist[i];
    }
    long long iter = 0;
    long long total = 0;
    long long max1 = 0, max2 = 0;
    if (numberlist[0] > 0) {
      while (iter < n) {
        while (numberlist[iter] > 0) {
          if (max1 == 0) max1 = numberlist[iter];
          max1 = max(max1, numberlist[iter]);
          iter++;
        }
        total += max1;
        max1 = 0;
        while (numberlist[iter] < 0) {
          if (max2 == 0) max2 = numberlist[iter];
          max2 = max(max2, numberlist[iter]);
          iter++;
        }
        total += max2;
        max2 = 0;
      }
    } else {
      while (iter < n) {
        while (numberlist[iter] < 0) {
          if (max2 == 0) max2 = numberlist[iter];
          max2 = max(max2, numberlist[iter]);
          iter++;
        }
        total += max2;
        max2 = 0;
        while (numberlist[iter] > 0) {
          if (max1 == 0) max1 = numberlist[iter];
          max1 = max(max1, numberlist[iter]);
          iter++;
        }
        total += max1;
        max1 = 0;
      }
    }
    cout << total << endl;
  }
}
