#include <bits/stdc++.h>
const double pie = 3.141592653589793238463;
using namespace std;
long long int myXOR(unsigned long long int x, unsigned long long int y) {
  return (x | y) & (~x | ~y);
}
long long int powerLL(long long int x, long long int n) {
  long long int result = 1;
  while (n) {
    if (n & 1) result = result * x % 1000000007;
    n = n / 2;
    x = x * x % 1000000007;
  }
  return result;
}
int main() {
  long long int t, n, m, i, j, k, l, x, y, z, a, b, c, d, e, p, nl, np, q, r, s;
  string str, str1;
  cin >> t;
  k = 0;
  while (t--) {
    cin >> n;
    long long int arr[n];
    for (i = 0; i < n; i++) cin >> arr[i];
    s = 0;
    long long int maxx = arr[0];
    for (i = 0; i < n - 1; i++) {
      if (arr[i + 1] * arr[i] > 0) {
        maxx = max(maxx, arr[i + 1]);
      } else {
        s += maxx;
        maxx = arr[i + 1];
      }
    }
    s += maxx;
    cout << s << endl;
  }
}
