#include
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t,x,y;
cin>>t;
while(t)
{ y=0;
cin>>x;
while(x)
{ if(x%10==4)
{y++;
x/=10;
}
else
{continue;
x/=10;
}
}
cout<<y<<endl;
t--;
}
return 0;
}
#include
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t,x,y;
cin>>t;
while(t)
{ y=0;
cin>>x;
while(x)
{ if(x%10==4)
{y++;
x/=10;
}
else
{continue;
x/=10;
}
}
cout<<y<<endl;
t--;
}
return 0;
}