#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j, n, t, sum = 0, ret, ret1;
  cin >> n;
  while (n--) {
    sum = 0, ret = 0, ret1 = -9999999999;
    cin >> t;
    long long ara[t];
    for (i = 0; i < t; i++) {
      cin >> ara[i];
    }
    for (i = 0; i < t; i++) {
      if (ara[i] > 0) {
        if (ara[i] > 0 && ara[i - 1] < 0) {
          sum += ret1;
          ret1 = -9999999999;
        }
        if (ara[i] > ret) ret = ara[i];
      } else if (ara[i] < 0) {
        if (ara[i] < 0 && ara[i - 1] > 0) {
          sum += ret;
          ret = 0;
        }
        if (ara[i] > ret1) ret1 = ara[i];
      }
    }
    if (ret != 0) sum += ret;
    if (ret1 != -9999999999) sum += ret1;
    cout << sum << "\n";
  }
  return 0;
}
