#include #include #include #include #include #include #include #include using namespace std; typedef long long LL; string str; int main(){ int t; cin >> t; while(t--){ LL cnt = 0, ans = 0; cin >> str; int len = str.length(); for(int i = 0; i < len; i++){ if(str[i] == 'q'){ cnt++; continue; } if(str[i] != 'q'){ ans += (cnt+1)*cnt/2; cnt = 0; } } if(cnt > 0){ ans += (cnt+1)*cnt/2; } cout << ans << endl; } return 0; }