#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, sum = 0, mx = -1e12, k, cntr = 1;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
      long long c;
      cin >> c;
      if (mx < 0) {
        if (c > 0) {
          if (cntr == 1) {
            mx = max(mx, c);
          } else {
            sum += mx;
            mx = max(mx, c);
          }
        } else {
          mx = max(mx, c);
        }
      } else {
        if (c > 0) {
          mx = max(mx, c);
        } else {
          sum += mx;
          mx = min(mx, c);
        }
      }
      cntr++;
    }
    cin >> k;
    if (mx > 0) {
      if (k > 0) {
        mx = max(mx, k);
        sum += mx;
      } else {
        sum += mx;
        sum += k;
      }
    } else {
      if (k > 0) {
        sum += mx;
        sum += k;
      } else {
        mx = max(mx, k);
        sum += mx;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
