#include<bits/stdc++.h>
using namespace std;
#define int long long
void sol(){
string s;
cin >> s;
int c = 0, ans = 0;
for(char ch:s){
if(ch == '1') c++;
else ans += c;
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> t;
while(t--){
sol();
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCnZvaWQgc29sKCl7CiAgICBzdHJpbmcgczsKICAgIGNpbiA+PiBzOwogICAgaW50IGMgPSAwLCBhbnMgID0gMDsKICAgIGZvcihjaGFyIGNoOnMpewogICAgICAgIGlmKGNoID09ICcxJykgYysrOwogICAgICAgIGVsc2UgYW5zICs9IGM7CiAgICB9CiAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwp9CnNpZ25lZCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBjb3V0LnRpZShOVUxMKTsKICAgIGludCB0ID0gMTsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBzb2woKTsKICAgIH0KICAgIHJldHVybiAwOwp9