#include<bits/stdc++.h>
using namespace std;
int hasSeven(int d){
int flag=0;
while(d!=0){
if(d%10==7){
flag=1;
break;
}
d/=10;
}
return flag;
}
int main(){
int n,num,k=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>num;
k=0;
for(int j=1;j<=num;j++){
if(hasSeven(j)) k++;
}
cout<<num-k<<endl;
}
return 0;
}