#include #include #include #include #include #include #define M 100007 #define LL long long using namespace std; int rd(){ int res=0,k=1;char c; while(c=getchar(),!isdigit(c)&&c!='-'); if(c=='-'){k=-1;c=getchar();} do{ res=(res<<3)+(res<<1)+(c^48); }while(c=getchar(),isdigit(c)); return res*k; } int cas,L[M],R[M]; LL sum; char str[M]; int main(){ cas=rd(); while(cas--){ sum=0; scanf("%s",str+1); int len=strlen(str+1); for(int i=1;i<=len;i++){ if(str[i]=='q'){ int val=1; int j=i; while(str[j+1]=='q')j++; int len=j-i+1; sum+=1ll*len*(len+1)/2; i=j; } } cout<