#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 100005;
vector<vector<int>> good_subs;
void genGoodSubs() {
for (int i = 1; i <= 9; i++) {
good_subs.push_back({i});
}
for (int i = 1; i + 3 <= 9; i++) {
good_subs.push_back({i, i + 3});
}
for (int i = 1; i <= 2; i++) {
for (int j = 0; j <= 6; j += 3) {
int first_val = i + j;
good_subs.push_back({first_val, first_val + 1});
}
}
good_subs.push_back({1, 2, 4, 5});
good_subs.push_back({2, 3, 5, 6});
good_subs.push_back({4, 5, 7, 8});
good_subs.push_back({5, 6, 8, 9});
}
int dp[MAXN][1 << 10];
void solve() {
string S;
cin >> S;
int N = S.size();
// Initialize DP table
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i < N; i++) {
for (int mask = 0; mask < (1 << 10); mask++) {
if (dp[i][mask] == 0) continue;
for (const auto &sub : good_subs) {
bool valid = true;
int new_mask = 0;
for (int d : sub) {
if (S[i] == '0' + d) {
new_mask< d);
} else {
valid = false;
break;
}
}
if (valid) {
dp[i + 1][new_mask] = (dp[i + 1][new_mask] + dp[i][mask]) % MOD;
}
}
}
}
int ans = 0;
for (int mask = 0; mask < (1 << 10); mask++) {
ans = (ans + dp[N][mask]) % MOD;
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
genGoodSubs();
int T;
cin >> T;
while (T--) {
solve();
}