#include #include //小数点出力用 //cout << fixed << setprecision(10) << ans; #include #include #include #include #include #include #include #include using ll = long long; using namespace std; #define modPHash (ll)((1LL<<61)-1) #define modP (ll)998244353 bool chkrng0idx(int pos, int sup) { return (0 <= pos && pos < sup); } int clk4(int num) { return (num - 2) * (num % 2); } void yn(bool tf) { cout << (tf ? "Yes\n" : "No\n"); } #define off 1010000 struct CM { // 大小比較用の関数オブジェクトを定義することもできる bool operator()(const pair,int>& a, const pair, int>& b) const noexcept { if (a.first.first >= 0 && b.first.first >= 0) { if (a.first.first * b.first.second == a.first.second * b.first.first)return a.second < b.second; return a.first.first * b.first.second < a.first.second * b.first.first; } else if (a.first.first < 0 && b.first.first >= 0) { return 0; } else if (a.first.first >= 0 && b.first.first < 0) { return 1; } if (a.first.first * b.first.second == a.first.second * b.first.first)return a.second < b.second; return a.first.first * b.first.second > a.first.second * b.first.first; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int Q; cin >> Q; while(Q--) { int N; string S; cin >> N >> S; int ans = 0; bool minus = 0; for (int i = 0;i < N;i++) { if (S[i] == '+') { if (!minus) { ans += 9; } minus = 0; } else if (S[i] == '-') { if (!minus) { ans += 9; } minus = 1; } else if (S[i] == '*') { if (!minus) { ans += 9; } } else { if (minus) { ans += S[i] - 0x31; } else { ans += 0x39 - S[i]; } } } cout << ans << "\n"; } }