------------------------------------------------------------------------------------------
//solution<1>:
------------------------------------------------------------------------------------------
#include<iostream>
#include<string>
using namespace std;
int main()
{
int t, n, count;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> n;
string s = to_string(n);
count = 0;
for (int i = 0; i < s.length(); i++)
{
if (s[i] == '4')
count++;
}
cout << count << "\n";
}
return 0;
}
------------------------------------------------------------------------------------------
//solution<2>:
------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
int main()
{
int t, n, count, x;
cin >> t;
for (int i = 0; i < t; i++)
{
cin >> n;
count = 0;
while(n!=0)
{
x = n % 10;
if (x == 4)
{
count++;
}
n /= 10;
}
cout << count << "\n";
}
return 0;
}