#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  while (a--) {
    long long b;
    cin >> b;
    long long c[b];
    for (int i = 0; i < b; i++) {
      cin >> c[i];
    }
    if (c[0] < 0 && c[b - 1] > 0) {
      long long k = 0, s = c[k], sum = 0;
      while (k < b) {
        while (c[k] < 0 && k < b) {
          s = fmax(c[k], s);
          k += 1;
        }
        sum += s;
        s = c[k];
        while (c[k] > 0 && k < b) {
          s = fmax(c[k], s);
          k += 1;
        }
        sum += s;
        s = c[k];
      }
      cout << sum << endl;
    } else {
      long long k = 0, s = 0, sum = 0;
      while (k < b) {
        while (c[k] > 0 && k < b) {
          s = fmax(c[k], s);
          k += 1;
        }
        sum += s;
        s = c[k];
        while (c[k] < b && k < b) {
          s = fmax(c[k], s);
          k += 1;
        }
        sum += s;
        s = c[k];
      }
      cout << sum << endl;
    }
  }
}
