#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T1, class T2>
struct cmpf {
  bool rev;
  inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {
    return (a.first < b.first) ^ rev;
  }
  cmpf(bool b = false) { rev = b; }
};
template <class T1, class T2>
struct cmps {
  bool rev;
  inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {
    return (a.second < b.second) ^ rev;
  }
  cmps(bool b = false) { rev = b; }
};
string to_string(const char& c) { return string(1, c); }
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(const bool& b) { return (b ? "true" : "false"); }
string to_string(const vector<bool>& v, const string& sep = " ") {
  string s = "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) {
      s += sep;
    }
    s += to_string(v[i]);
  }
  return s + "]";
}
template <size_t N>
string to_string(const bitset<N>& v) {
  string s = "[";
  for (size_t i = 0; i < N; i++) s += v[i] ? '1' : '0';
  return s + "]";
}
template <class T1, class T2>
string to_string(const pair<T1, T2>& p, const string& sep = ",");
template <class T>
string to_string(const T& v, const string& sep = " ") {
  bool first = true;
  string s = "{";
  for (const auto& x : v) {
    if (!first)
      s += sep;
    else
      first = false;
    s += to_string(x);
  }
  return s + "}";
}
template <class T>
string to_string(const T& v, const int& sz, const string& sep = " ") {
  string s = "[";
  for (int i = 0; i < sz; i++) {
    if (i) {
      s += sep;
    }
    s += to_string(v[i]);
  }
  return s + "]";
}
template <class T1, class T2>
string to_string(const pair<T1, T2>& p, const string& sep) {
  return "(" + to_string(p.first) + sep + to_string(p.second) + ")";
}
long long binpow(const long long& x, const long long& p, const long long& mod) {
  assert(mod > 0);
  if (p == 0) return 1;
  if (p == 1) return x % mod;
  if (p & 1) return (binpow((x * x) % mod, p / 2, mod) * x) % mod;
  return binpow((x * x) % mod, p / 2, mod) % mod;
}
template <class T>
void chmn(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmx(T& a, const T& b) {
  if (a < b) a = b;
}
void setIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const long long MOD = 1e9 + 7;
const int INIT = 1001001001;
const int MN = -1;
void solve() {
  string s;
  cin >> s;
  long long depth = 0;
  long long target = 1;
  long long ans = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') {
      depth--;
    } else {
      depth++;
    }
    if (depth == target) {
      ans += i + 1;
      target++;
    }
  }
  cout << ans << endl;
}
int main() {
  setIO();
  long long T = 1;
  cin >> T;
  while (T--) solve();
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: 
    
    
    res = 0  
    for init = 0 to inf  
        cur = init  
        ok = true  
        for i = 1 to |s|  
            res = res + 1  
            if s[i] == '+'  
                cur = cur + 1  
            else  
                cur = cur - 1  
            if cur < 0  
                ok = false  
                break  
        if ok  
            break  
    

Note that the inf denotes infinity, and the characters of the string are numbered from 1 to |s|.

You have to calculate the value of the res after the process ends.

Input

The first line contains one integer t (1 ≤ t ≤ 1000) — the number of test cases.

The only lines of each test case contains string s (1 ≤ |s| ≤ 10^6) consisting only of characters + and -.

It's guaranteed that sum of |s| over all test cases doesn't exceed 10^6.

Output

For each test case print one integer — the value of the res after the process ends.

Example

Input


3
--+-
---
++--+-


Output


7
9
6

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T1, class T2>
struct cmpf {
  bool rev;
  inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {
    return (a.first < b.first) ^ rev;
  }
  cmpf(bool b = false) { rev = b; }
};
template <class T1, class T2>
struct cmps {
  bool rev;
  inline bool operator()(const pair<T1, T2>& a, const pair<T1, T2>& b) const {
    return (a.second < b.second) ^ rev;
  }
  cmps(bool b = false) { rev = b; }
};
string to_string(const char& c) { return string(1, c); }
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(const bool& b) { return (b ? "true" : "false"); }
string to_string(const vector<bool>& v, const string& sep = " ") {
  string s = "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) {
      s += sep;
    }
    s += to_string(v[i]);
  }
  return s + "]";
}
template <size_t N>
string to_string(const bitset<N>& v) {
  string s = "[";
  for (size_t i = 0; i < N; i++) s += v[i] ? '1' : '0';
  return s + "]";
}
template <class T1, class T2>
string to_string(const pair<T1, T2>& p, const string& sep = ",");
template <class T>
string to_string(const T& v, const string& sep = " ") {
  bool first = true;
  string s = "{";
  for (const auto& x : v) {
    if (!first)
      s += sep;
    else
      first = false;
    s += to_string(x);
  }
  return s + "}";
}
template <class T>
string to_string(const T& v, const int& sz, const string& sep = " ") {
  string s = "[";
  for (int i = 0; i < sz; i++) {
    if (i) {
      s += sep;
    }
    s += to_string(v[i]);
  }
  return s + "]";
}
template <class T1, class T2>
string to_string(const pair<T1, T2>& p, const string& sep) {
  return "(" + to_string(p.first) + sep + to_string(p.second) + ")";
}
long long binpow(const long long& x, const long long& p, const long long& mod) {
  assert(mod > 0);
  if (p == 0) return 1;
  if (p == 1) return x % mod;
  if (p & 1) return (binpow((x * x) % mod, p / 2, mod) * x) % mod;
  return binpow((x * x) % mod, p / 2, mod) % mod;
}
template <class T>
void chmn(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmx(T& a, const T& b) {
  if (a < b) a = b;
}
void setIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int chr[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int chc[8] = {0, 1, 0, -1, -1, 1, -1, 1};
const long long MOD = 1e9 + 7;
const int INIT = 1001001001;
const int MN = -1;
void solve() {
  string s;
  cin >> s;
  long long depth = 0;
  long long target = 1;
  long long ans = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '+') {
      depth--;
    } else {
      depth++;
    }
    if (depth == target) {
      ans += i + 1;
      target++;
    }
  }
  cout << ans << endl;
}
int main() {
  setIO();
  long long T = 1;
  cin >> T;
  while (T--) solve();
  return 0;
}

```