#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <string>
#include <ios>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>

#define  FASTIO ios_base::sync_with_stdio(0);cin.tie(NULL);
#define CY   cout<<"YES"<<endl
#define CN   cout<<"NO"<<endl
#define endl '\n'
#define ll   long long
#define pshb  push_back
#define sz  size()
#define vec vector<int>
#define vecl vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

using namespace std;

ll gcd(ll n1, ll n2)
{
    if (n2 != 0) return gcd(n2, n1 % n2);
    else return n1;
}
ll lcm(ll a, ll b) {
    return a * b / (gcd(a, b));
}

ll pv(ll a, ll b) {
    if (b == 0)return 1;
    ll res = (pv(a, b / 2));
    if (b % 2)   return res * res * a;
    else return res * res;
}

void solve() {
    string s; cin >> s;
    vecl calc(s.sz + 5);
    calc[1] = 1;
    for (int i = 2; i < calc.sz; i++) {
        calc[i] = 2 * calc[i - 1] + 2;
        calc[i] %= MOD;
    }
    bool f = 0;
    for (int i = 0; i < s.sz; i++) {
        if (s[i] != '1' && s[i] != '0') {
            int a = s[s.sz - 1] - '0';
            if (a % 2 == 0)s[i] = '0';
            else s[i] = '1';
            f = 1;
        }
    }
   // cout << s << endl;
    ll ans = f;
    ll cur = 0;
    for (int i = s.sz - 1; i >= 0; i--) {
        if (s[i] == '0')cur++;
        else {
            if (cur)ans += calc[cur] + 2;
            else ans++;
            ans %= MOD;
            cur++;
        }
    }
    cout << ans << endl;
}



signed main() {
    FASTIO
        //freopen("planting.in", "r", stdin);
  // freopen("planting.out", "w", stdout);
        int t; cin >> t;
    while (t--)
        solve();
}