#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
void fum(int n);
fum(n);
return 0;
}
void fum(int n)
{
int a[n],b[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
b[i]=0;
}
for(int p=0;p<n;p++)
{
for(int u=1;u<=a[p];u++)
{
for(int y=u;y!=0;y=y/10)
if(y%10==7)
{
b[p]++;
break;
}
}
}
for(int r=0;r<n;r++)
cout<<a[r]-b[r]<<endl;
}