#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    int a[n], p = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '+')
        a[i] = 1;
      else
        a[i] = -1;
    }
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      p += a[i];
      if (p >= 0) continue;
      if (mp.find(p) == mp.end()) mp.insert(make_pair(p, i + 1));
    }
    long long res = 0LL;
    for (auto it = mp.begin(); it != mp.end(); it++) {
      res += (it->second);
    }
    res += n;
    cout << res << endl;
  }
}
