#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long double PI = 3.14159265358979323;
int main() {
  long long t, n, a[100000], ms = 0, sum = 0, dl = 1, mdl = 0;
  bool zn;
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (a[0] > 0)
      zn = 1;
    else
      zn = 0;
    sum += a[0];
    ms = sum;
    for (int i = 1; i < n; i++) {
      if (zn) {
        if (a[i] > 0) {
          sum = a[i];
          dl = 1;
          continue;
        } else {
          sum += a[i];
          zn = 0;
          dl++;
        }
      } else {
        if (a[i] < 0) {
          sum = a[i];
          dl = 1;
          continue;
        } else {
          sum += a[i];
          zn = 1;
          dl++;
        }
      }
      if (dl > mdl || (dl != 1 && mdl != 1)) {
        if (mdl > dl)
          ms = sum;
        else
          ms = max(ms, sum);
        mdl = dl;
      }
    }
    cout << ms << '\n';
    sum = ms = mdl = 0;
    dl = 1;
  }
  return 0;
}
