#include using namespace std; typedef long long ll; char str[105000]; int main() { int t; scanf("%d", &t); while(t--) { scanf("%s", str); int len=strlen(str); str[len]='a'; ll ans=0; ll tmp=0; for(int i=0;i<=len;i++) { if(str[i]=='q'){tmp++;continue;} else { if(tmp==0)continue; else { ans+=tmp*(tmp+1)/2; tmp=0; } } } printf("%I64d\n", ans); } }