#include <bits/stdc++.h>
using namespace std;
int dir1[6][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, 1}};
int dir2[6][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, -1}, {-1, -1}};
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979;
const int mod = 1e9 + 7;
const int N = 30005;
inline long long read() {
  long long x = 0;
  bool f = true;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = false;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return f ? x : -x;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int fg = 0;
    if (a[0] > 0) fg = 1;
    long long res = 0;
    int fist = a[0], tmp = a[0];
    for (int i = 0; i < n; i++) {
      if (fg) {
        if (a[i] < 0) {
          fg = 0;
          res += tmp;
          tmp = a[i];
        } else {
          tmp = max(tmp, a[i]);
        }
      } else {
        if (a[i] > 0) {
          fg = 1;
          res += tmp;
          tmp = a[i];
        } else {
          tmp = max(tmp, a[i]);
        }
      }
    }
    res += tmp;
    cout << res << endl;
  }
  return 0;
}
