#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long res = 0;
    vector<long long> a;
    long long ff = 0, maxer = 100000, ruk;
    bool flag = false;
    for (long long i = 0; i < s.length(); i++) {
      res++;
      if (s[i] == '+')
        ff++;
      else
        ff--;
      a.push_back(ff);
    }
    long long n = res;
    if (!flag) {
      long long x = 0;
      res = 0;
      bool found = false;
      long long xx = 0;
      for (long long i = 0; i < n; i++) {
        found = false;
        a[i] += x;
        res++;
        while (a[i] < 0) {
          res += i + 1;
          x++;
          a[i]++;
          found = true;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
