#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long long a;
    cin >> a;
    n--;
    long long g;
    long long s = 0;
    while (n--) {
      cin >> g;
      if (g * a > 0) {
        if (g > a) {
          a = g;
        }
      } else {
        s += a;
        a = g;
      }
    }
    cout << s + a << endl;
  }
  return 0;
}
