#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    map<int, int> m;
    long long ans = 0LL;
    int c = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '-')
        c++;
      else
        c--;
      if (c > 0) {
        if (m[c] == 0) {
          m[c] = 1;
          ans = ans + (long long)i + 1;
        }
      }
    }
    cout << ans + (long long)s.size() << "\n";
  }
  return 0;
}
