#include <bits/stdc++.h>
using namespace std;
int main() {
  bool b;
  int t;
  cin >> t;
  long long sum[t];
  int a[20000];
  int n;
  int m;
  bool c;
  for (int z = 0; z < t; z++) {
    sum[z] = 0;
    cin >> n;
    cin >> a[0];
    m = a[0];
    if (a[0] > 0)
      b = true;
    else
      b = false;
    for (int y = 1; y < n; y++) {
      cin >> a[y];
      if (a[y] > 0)
        c = true;
      else
        c = false;
      if (c == b) {
        if (a[y] > m) m = a[y];
        if (y == (n - 1)) sum[z] += m;
      } else {
        sum[z] += m;
        b = c;
        m = a[y];
        if (y == (n - 1)) sum[z] += m;
      }
    }
  }
  for (int x = 0; x < t; x++) cout << sum[x] << endl;
  return 0;
}
