#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define db(…) __f(#VA_ARGS, VA_ARGS)
template
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << ‘\n’; }
template <typename Arg1, typename… Args>
void __f(const char* names, Arg1&& arg1, Args&&… args) {
const char* comma = strchr(names + 1, ‘,’);
cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args…);
}
const int N = 100005;
int32_t main()
{
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("/home/sarthakgrover/Paytm/Code/C++/input.txt", “r”, stdin);
freopen("/home/sarthakgrover/Paytm/Code/C++/output.txt", “w”, stdout);
#endif
int t; cin >> t; while (t–)
{
int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
// cin>>n;
string s;
cin>>s;
n=s.length();
int dp[n+1];
dp[n]=1;
for (i = n-1; i >=0; i–)
{
dp[i]=dp[i+1];
if(i!=n-1) {
j=s[i]-‘0’;
if(j<3) {
k=s[i+1]-‘0’;
if(j==1) {
dp[i]+=dp[i+2];
}
else if(j==2&&k<7)
{
dp[i]+=dp[i+2];
}
}
}
}
cout<<dp[0]<<endl;
}
}