#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (long long int i = 0; i < n; i++) cin >> arr[i];
    long long int flag, pos = 0, neg = 0, sumr = 0;
    for (long long int i = 0; i < n; i++) {
      if (i == 0) {
        if (arr[i] > 0)
          flag = 1, pos = arr[i];
        else
          flag = -1, neg = arr[i];
        continue;
      }
      if (arr[i] > 0) {
        if (flag == -1) {
          sumr += neg;
          neg = 0;
          pos = arr[i];
          flag = 1;
          if (i == n - 1) sumr += pos;
        } else {
          pos = max(pos, arr[i]);
          if (i == n - 1) {
            sumr += pos;
          }
        }
      } else {
        if (flag == 1) {
          sumr += pos;
          pos = 0;
          neg = arr[i];
          flag = -1;
          if (i == n - 1) sumr += neg;
        } else {
          neg = max(neg, arr[i]);
          if (i == n - 1) sumr += neg;
        }
      }
    }
    cout << sumr << endl;
  }
}
