#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long int res = 0;
  long long int n = s.length();
  long long int init = 0;
  long long int cur = init;
  long long int ok = 1;
  long long int i = -1;
  long long int ans = 0;
  long long int prev = 0;
  for (int j = 0; j < 1000001; j++) {
    ok = 1;
    cur = 0;
    for (i += 1; i < n; i++) {
      prev += 1;
      if (s[i] == '+')
        cur++;
      else
        cur--;
      if (cur < 0) {
        ok = 0;
        ;
        break;
      }
    }
    ans += prev;
    res += prev;
    if (ok) break;
    res += ans;
    prev = 0;
  }
  cout << res << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}
