#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;
}