#include using namespace std; int main() { int t; cin >> t; getchar(); while(t--) { string str; getline(cin , str); long long ans = 0; long long tmp = 0; if(str.size() == 0) { cout << 0 << endl; continue; } if(str[0] == 'q') { tmp++; } for(int i = 1 ; i < str.size() ; ++i) { if(str[i] == 'q') { tmp++; } else { if(str[i - 1] == 'q') { ans += ((tmp + 1)*(tmp)) >> 1; tmp = 0; } } } if(tmp) { ans += ((tmp + 1) * (tmp)) >> 1; } cout << ans << endl; } return 0; }