#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
// ordered_set <int> s  ;
// auto x=s.find_by_order(k);
// s.order_of_key(val);

ll to_int(string s){
  ll p=1, ans=0;
  int n=s.length();
  for(int i=n-1;i>=0;i--){
    ans+=p*(s[i]-'0');
    p*=2;
  }
  return ans;
}

void print(ll x, int m){
  // if(x==0){
  //   cout<<0;
  //   return ;
  // }
  vector<int> ans;
  while(x){
    ans.eb(x%2);
    x/=2;
  }
  while(ans.size()<m)
    ans.eb(0);
  reverse(all(ans));
  for(auto i:ans)
    cout<<i;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
      ll n,m; cin>>n>>m;
      ll val = (1<<m); val--;

      vector<string > s(n);
      for(int i=0;i<n;i++)
        cin>>s[i];

      vector<ll> a(n);
      for(int i=0;i<n;i++){
        a[i]=to_int(s[i]);
      }

      sort(all(a));
      val=(val-n)/2;

      for(int i=0;i<n;i++)
        if(a[i]<=val)
          val++;

      print(val, m);
      cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
// ordered_set <int> s  ;
// auto x=s.find_by_order(k);
// s.order_of_key(val);

ll to_int(string s){
  ll p=1, ans=0;
  ll n=s.length();
  for(int i=n-1;i>=0;i--){
    ans+=p*(s[i]-'0');
    p*=2;
  }
  return ans;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
      int n,m; cin>>n>>m;
      ll val = (1<<m);

      vector<ll > a(n);
      for(int i=0;i<n;i++){
        string s; cin>>s;
        a[i]=stoll(s, nullptr, 2);
      }

      sort(all(a));
      val=(val-n-1)/2;

      for(int i=0;i<n;i++)
        if(a[i]<=val)
          val++;

      for(int i=m-1;i>=0;i--)
        cout<<(val>>i&1);
      cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

int main() {
  ios::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  int t;
  cin>>t;
  while(t--) {
      int m,n;
        cin>>n>>m;
        vector<ll> v(n);
        ll ans= ((1LL<<m)-n-1)/2;
    for(int i=0;i<n;++i){
        string s;
        cin>>s;
        v[i]=stoll(s,nullptr,2);
        }
        sort(v.begin(),v.end());

        for(auto num:v)
          ans+=(num<=ans);

        for(int i=m-1;i>=0;--i){
            cout<<(ans>>i&1);
        }
        // cout<<ans<<"\n";
        cout<<"\n";
  }
}


#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
// ordered_set <int> s  ;
// auto x=s.find_by_order(k);
// s.order_of_key(val);

ll to_int(string s){
  ll p=1, ans=0;
  int n=s.length();
  for(int i=n-1;i>=0;i--){
    ans+=p*(s[i]-'0');
    p*=2;
  }
  return ans;
}

void print(ll x, int m){
  if(x==0)
    cout<<0;
  vector<int> ans;
  while(x){
    ans.eb(x%2);
    x/=2;
  }
  reverse(all(ans));
  for(int i=0;i<m-ans.size();i++)
    cout<<0;
  for(auto i:ans)
    cout<<i;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
      int n,m; cin>>n>>m;
      ll val = (1<<m); val--;

      vector<string > s(n);
      for(int i=0;i<n;i++)
        cin>>s[i];

      vector<ll> a(n);
      for(int i=0;i<n;i++){
        a[i]=to_int(s[i]);
      }

      sort(all(a));
      val=(val-n)/2;

      for(int i=0;i<n;i++)
        if(a[i]<=val)
          val++;

      print(val, m);
      cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
// ordered_set <int> s  ;
// auto x=s.find_by_order(k);
// s.order_of_key(val);

ll to_int(string s){
  ll p=1, ans=0;
  int n=s.length();
  for(int i=n-1;i>=0;i--){
    ans+=p*(s[i]-'0');
    p*=2;
  }
  return ans;
}

void print(ll x, int m){
  // if(x==0){
  //   cout<<0;
  //   return ;
  // }
  vector<int> ans;
  while(x){
    ans.eb(x%2);
    x/=2;
  }
  while(ans.size()<m)
    ans.eb(0);
  reverse(all(ans));
  for(auto i:ans)
    cout<<i;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
      ll n,m; cin>>n>>m;
      ll val = (1ll<<m); val--;

      vector<string > s(n);
      for(int i=0;i<n;i++)
        cin>>s[i];

      vector<ll> a(n);
      for(int i=0;i<n;i++){
        a[i]=to_int(s[i]);
      }

      sort(all(a));
      val=(val-n)/2;

      for(int i=0;i<n;i++)
        if(a[i]<=val)
          val++;

      print(val, m);
      cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
/*   -- AUTHOR --
  ---- cervotrex ----
*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(arr) arr.begin(),arr.end()
#define mod 1000000007
const ll INF = 1LL << 60;
const int MAX_N = 1000005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
// ordered_set <int> s  ;
// auto x=s.find_by_order(k);
// s.order_of_key(val);

ll to_int(string s){
  ll p=1, ans=0;
  int n=s.length();
  for(int i=n-1;i>=0;i--){
    ans+=p*(s[i]-'0');
    p*=2;
  }
  return ans;
}

void print(ll x, int m){
  vector<int> ans;
  while(x){
    ans.eb(x%2);
    x/=2;
  }
  while(ans.size()<m)
    ans.eb(0);
  reverse(all(ans));
  for(auto i:ans)
    cout<<i;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    cin>>t;
    while(t--){
      int n,m; cin>>n>>m;
      ll val = (1<<m); val--;

      vector<string > s(n);
      for(int i=0;i<n;i++)
        cin>>s[i];

      vector<ll> a(n);
      for(int i=0;i<n;i++){
        a[i]=to_int(s[i]);
      }

      sort(all(a));
      val=(val-n)/2;

      for(int i=0;i<n;i++)
        if(a[i]<=val)
          val++;

      // print(val, m);
      for(int i=m-1;i>=0;--i)
        cout<<(val>>i&1);
      cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    ll n,m;
    cin>>n>>m;
    ll cur = ((1LL<<m)-1)>>1LL;
    int rem=(1LL<<m);
    for(int i=0;i<n;++i) {
        string s;
        cin>>s;
        bitset<61>tt(s);
        ll x=tt.to_ulong();
        if(!(rem&1)) {
            if(x<=cur)cur++;
        }
        else {
            if(x>=cur)cur--;
        }
        rem--;
    }
    vector<int>ar;
    if(cur==0) {
        while(m--)cout<<0;
        cout<<"\n";
        return;
    }
    while(cur) {
        ar.push_back(cur&1) , cur>>=1LL;
    }
    while((int)ar.size()<m)ar.push_back(0);
    for(int i=(int)ar.size()-1;i>=0;i--)
        cout<<ar[i];
    cout<<"\n";
}

int main(){
    fastio
    int test=1;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    map<ll,bool>res;
    ll n,m;
    cin>>n>>m;
    ll cur = ((1LL<<m)-1LL)>>1LL;
    ll rem=(1LL<<m);
    for(int i=0;i<n;++i) {
        string s;
        cin>>s;
        bitset<61>tt(s);
        ll x=tt.to_ullong();
        res[x]=1;
        if(!(rem&1LL)) {
            if(x<=cur) {
                cur++;
                while(res[cur])cur++;
            }
        }
        else {
            if(x>=cur) {
                cur--;
                while(res[cur])cur--;
            }
        }
        rem--;
    }
    vector<int>ar;
    if(cur==0) {
        while(m--)cout<<0;
        cout<<"\n";
        return;
    }
    while(cur) {
        ar.push_back(cur&1) , cur>>=1LL;
    }
    while((int)ar.size()<m)ar.push_back(0);
    for(int i=(int)ar.size()-1;i>=0;i--)
        cout<<ar[i];
    cout<<"\n";
}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    map<ll,bool>res;
    ll n,m;
    cin>>n>>m;
    ll cur = ((1LL<<m)-1LL)>>1LL;
    ll rem=(1LL<<m);
    for(int i=0;i<n;++i) {
        string s;
        cin>>s;
        bitset<61>tt(s);
        ll x=tt.to_ulong();
        res[x]=1;
        if(!(rem&1LL)) {
            if(x<=cur) {
                cur++;
                while(res[cur])cur++;
            }
        }
        else {
            if(x>=cur) {
                cur--;
                while(res[cur])cur--;
            }
        }
        rem--;
    }
    vector<int>ar;
    if(cur==0) {
        while(m--)cout<<0;
        cout<<"\n";
        return;
    }
    while(cur) {
        ar.push_back(cur&1) , cur>>=1LL;
    }
    while((int)ar.size()<m)ar.push_back(0);
    for(int i=(int)ar.size()-1;i>=0;i--)
        cout<<ar[i];
    cout<<"\n";
}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    map<ll,bool>res;
    ll n,m;
    cin>>n>>m;
    ll cur = ((1LL<<m)-1)>>1LL;
    ll rem=(1LL<<m);
    for(int i=0;i<n;++i) {
        string s;
        cin>>s;
        bitset<61>tt(s);
        ll x=tt.to_ulong();
        res[x]=1;
        if(!(rem&1)) {
            if(x<=cur) {
                cur++;
                while(res[cur])cur++;
            }
        }
        else {
            if(x>=cur) {
                cur--;
                while(res[cur])cur--;
            }
        }
        rem--;
    }
    vector<int>ar;
    if(cur==0) {
        while(m--)cout<<0;
        cout<<"\n";
        return;
    }
    while(cur) {
        ar.push_back(cur&1) , cur>>=1LL;
    }
    while((int)ar.size()<m)ar.push_back(0);
    for(int i=(int)ar.size()-1;i>=0;i--)
        cout<<ar[i];
    cout<<"\n";
}

int main(){
    fastio
    int test;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    ll n,m;
    cin>>n>>m;
    ll cur = ((1LL<<m)-1)>>1LL;
    int rem=(1LL<<m);
    for(int i=0;i<n;++i) {
        string s;
        cin>>s;
        bitset<61>tt(s);
        ll x=tt.to_ulong();
        if(!(rem&1)) {
            if(x<=cur)cur++;
        }
        else {
            if(x>=cur)cur--;
        }
        rem--;
    }
    vector<int>ar;
    if(cur==0) {
        cout<<0<<"\n";
        return;
    }
    while(cur) {
        ar.push_back(cur&1) , cur>>=1LL;
    }
    while((int)ar.size()<m)ar.push_back(0);
    for(int i=(int)ar.size()-1;i>=0;i--)
        cout<<ar[i];
    cout<<"\n";
}

int main(){
    fastio
    int test=1;
    cin>>test;
    while(test--)
        solve();
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
ll ret(string s)
{
    ll c=0;
    ll ans=0;
    for(ll i=s.length()-1;i>=0;i--){
        ans+=(pow(2,c++)*(s[i]-'0'));
    }
    return ans;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> vs;
    vll v;
    ll tot=pow(2,m);
    ll rem=tot-n;
    ll mid = (rem-1)/2;
    for(ll i=1;i<=n;i++){
        string str;
        cin>>str;
        vs.pb(str);
        v.pb(ret(str));
    }
    sorty(v);
    for(auto x:v){
        if(mid>=x){
            mid++;
        }
    }
    string ans;
    for(ll i=m-1;i>=0;i--){
        if(mid&(1<<i))ans.pb('1');
        else ans.pb('0');
    }
    cout <<ans <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
ll ret(string s)
{
    ll c=0;
    ll ans=0;
    for(ll i=s.length()-1;i>=0;i--){
        if(s[i]=='1'){
            ans+=(pow(2,c));
        }
        c++;
    }
    return ans;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> vs;
    vll v;
    ll tot=pow(2,m);
    ll rem=tot-n;
    ll mid = (rem-1)/2;
    for(ll i=1;i<=n;i++){
        string str;
        cin>>str;
        vs.pb(str);
        v.pb(ret(str));
    }
    sorty(v);
    for(ll i=0;i<n;i++){
        if(mid>=v[i]){
            mid++;
        }
    }
    string ans="";
    for(ll i=m-1;i>=0;i--)
    {
        if((mid&(1ll<<i))==(1ll<<i))
            ans+='1';
        else
            ans+='0';
    }
    cout <<ans <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
ll ret(string s)
{
    ll c=0;
    ll ans=0;
    for(ll i=s.length()-1;i>=0;i--){
        if(s[i]=='1'){
            ans+=(pow(2,c));
        }
        c++;
    }
    return ans;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> vs;
    vll v;
    ll tot=pow(2,m);
    ll rem=tot-n;
    ll mid = (rem-1)/2;
    for(ll i=1;i<=n;i++){
        string str;
        cin>>str;
        vs.pb(str);
        v.pb(ret(str));
    }
    sorty(v);
    for(auto x:v){
        if(mid>=x){
            mid++;
        }
    }
    string ans;
    for(ll i=m-1;i>=0;i--){
        if((mid&(1<<i))==(1<<i))ans.pb('1');
        else ans.pb('0');
    }
    cout <<ans <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
ll ret(string s)
{
    ll c=0;
    ll ans=0;
    for(ll i=s.length()-1;i>=0;i--){
        if(s[i]=='1'){
            ans+=(pow(2,c));
        }
        c++;
    }
    return ans;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> vs;
    vll v;
    ll tot=pow(2,m);
    ll rem=tot-n;
    ll mid = (rem-1)/2;
    for(ll i=1;i<=n;i++){
        string str;
        cin>>str;
        vs.pb(str);
        v.pb(ret(str));
    }
    sorty(v);
    //cout <<mid <<"\n";
    for(ll i=0;i<n;i++){
        if(mid>=v[i]){
            mid++;
        }
    }

    string ans="";
    for(ll i=m-1;i>=0;i--)
    {
        if((mid&(1ll<<i)))
            ans+='1';
        else
            ans+='0';
    }
    cout <<ans <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   sz(s)         s.size()
#define   ll            long long int
#define   ull           unsigned ll
#define   ld            long double
#define   print(v)      for(ll i=0;i<v.size();i++)cout<<v[i]<<" "
#define   printpair(v)  for(ll i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second<<"\n"
#define   bmd           1000000007
#define   bmd1          998244353
#define   umll          unordered_map<ll,ll>
#define   mll           map<ll,ll>
#define   mcl           map<char,ll>
#define   pll           pair<ll,ll>
#define   F             first
#define   S             second
#define   setp(x)       setprecision(x)
#define   pb            push_back
#define   all(v)        v.begin(),v.end()
#define   tr(a)         for(auto it=a.begin();it!=a.end();it++)
#define   trr(a)        for(auto it1=a.begin();it1!=a.end();it1++)
#define   vll           vector<long long int>
#define   sorty(v)      sort(v.begin(),v.end())
#define   rsort(v)      sort(v.rbegin(),v.rend())
#define   PI            3.1415926535897932384626
#define   db()          cout<<"\n"<<"here"<<"\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

//---------------------------------------------------------------------------
const int MOD = bmd;
const int N=2e5+100;
inline  ll sqr(ll x){return x*x;}
inline  void normal(ll &a) { a = (a+MOD)%MOD; }
inline  ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline  ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline  ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline  ll modPow(ll b, ll p) { ll r = 1;b=b%MOD; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline  ll modInv(ll a) { return modPow(a, MOD-2); }
inline  ll modDiv(ll a,ll b) { return modMul(a, modInv(b)); }
//---------------------------------------------------------------------------
ll ret(string s)
{
    ll c=0;
    ll ans=0;
    for(ll i=s.length()-1;i>=0;i--){
        if(s[i]=='1'){
            ans+=(pow(2,c));
        }
        c++;
    }
    return ans;
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    vector<string> vs;
    vll v;
    ll tot=pow(2,m);
    ll rem=tot-n;
    ll mid = (rem-1)/2;
    for(ll i=1;i<=n;i++){
        string str;
        cin>>str;
        vs.pb(str);
        v.pb(ret(str));
    }
    sorty(v);
    cout <<mid <<"\n";
    for(ll i=0;i<n;i++){
        if(mid>=v[i]){
            mid++;
        }
    }

    string ans="";
    for(ll i=m-1;i>=0;i--)
    {
        if((mid&(1ll<<i)))
            ans+='1';
        else
            ans+='0';
    }
    cout <<ans <<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);//first give all input then gives output
    ll t;
    cin>>t;
    while(t--){
        solve();
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
ll tot;
ll ans;
int main(){
	//freopen("in.txt","r",stdin);
	int t;
	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		tot = (1LL<<m);  // 用1LL
		ll rem = tot - n;
		rem--;
		ll ind = rem / 2;
		vector<pll> vt;
		vector<string> vts;
		for(ll i=0;i<n;i++) {
			string s;
			cin>>s;
			vts.push_back(s);
		}
		sort(vts.begin(),vts.end());   //sort first
		for(ll i = 0;i<vts.size();i++){
			char ch[65];
			strcpy(ch,vts[i].c_str());
			char* ed;
			ll res = (ll)strtol(ch,&ed,2);
			vt.emplace_back(res,res-i-1);
		}
		//sort(vt.begin(),vt.end());
		vt.emplace_back((1LL<<m),(1LL<<m) - n-1);

		for(ll i=0;i<vt.size();i++){
			if(vt[i].second==ind){
				ans = vt[i].first - 1;break;
			}else if(vt[i].second>=ind){
				if(vt.size()==1 or i==0){
					ans = ind;break;
				}else{
					ans = vt[i-1].first + (ind - vt[i-1].second);break;
				}
			}
		}
//		char fans[65];
//		itoa(ans,fans,2);  //转换不了long long
//		char ffans[m+2];
//		fill(ffans,ffans+m+2,'0');
//		for(ll i=m-strlen(fans),j=0;j<strlen(fans);i++,j++){
//			ffans[i] = fans[j];
//		}
//		for(ll i=0;i<m;i++) cout<<ffans[i]; cout<<endl;

		for(ll i=m-1;i>=0;i--){
			cout<<(ans>>i&1);
		}puts("");

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
ll tot;
ll ans;
int main(){
	//freopen("in.txt","r",stdin);
	int t;
	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		tot = (1LL<<m);
		ll rem = tot - n;
		rem--;
		ll ind = rem / 2;
		vector<pll> vt;
		vector<string> vts;
		for(ll i=0;i<n;i++) {
			string s;
			cin>>s;
			vts.push_back(s);
		}
		sort(vts.begin(),vts.end());   //sort first
		for(ll i = 0;i<vts.size();i++){
			char ch[65];
			strcpy(ch,vts[i].c_str());
			char* ed;
			ll res = (ll)strtol(ch,&ed,2);
			vt.emplace_back(res,res-i-1);
		}
		//sort(vt.begin(),vt.end());
		vt.emplace_back((1LL<<m),(1LL<<m) - n-1);

		for(ll i=0;i<vt.size();i++){
			if(vt[i].second==ind){
				ans = vt[i].first - 1;break;
			}else if(vt[i].second>ind){
				if(vt.size()==1 or i==0){
					ans = ind;break;
				}else{
					ans = vt[i-1].first + (ind - vt[i-1].second);break;
				}
			}
		}
		char fans[65];
		itoa(ans,fans,2);
		char ffans[m+2];
		fill(ffans,ffans+m+2,'0');
		for(ll i=m-strlen(fans),j=0;j<strlen(fans);i++,j++){
			ffans[i] = fans[j];
		}
		for(ll i=0;i<m;i++) cout<<ffans[i]; cout<<endl;

	}

	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    long long i=0,a,b,n,m;
    scanf("%lld%lld\n",&n,&m);
    char s[100000],c,d;
    scanf("%s",s);

  // scanf("%lld",&m);
    while(i<m)
    {
       scanf ("%lld%lld %c %c",&a,&b,&c,&d);
        s[a-1]=c;
        s[b-1]=d;
        i++;
    }
    printf("%s",s);

}


#include <stdio.h>
int count (long long a){
int b = 0;
while (a){
	char c = a%10;
	if (c == 7 || c == 4)
		b++;
	a /=10;
}
return b;
}

int main (){
int i,n,k,sum = 0;
scanf("%i%i",&n,&k);

for (i=0;i<n;i++){
	long long a;
	scanf("%lli",&a);
	if (count(a)<=k)
		sum++;
	}
printf("%i",sum);
return 0;
}


#include<stdio.h>
int main()
{
    int n,k,cnt=0,i;
    scanf("%d%d",&n,&k);
    char s[100];
    while(n--)
    {
        int lucky=0;
        scanf("%s",s);
        for(i=0;i<strlen(s);i++)
        {
            if(s[i]=='4' || s[i]=='7')
            {
                lucky+=1;
            }
        }
        if(lucky<=k)
        {
            cnt+=1;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


#include<stdio.h>
int main()
{      long long int n,m,r,digit,lucky,c=0;
        scanf("%lld%lld",&n,&m);

        while(n--)
        {
              scanf("%lld",&r);
              lucky=0;
              while(r!=0)
              {
                  digit=r%10;
                  r/=10;
                if(digit==4 || digit==7)
                {
                    lucky++;
                }

              }
              if(lucky<=m)
              {
                  c++;
              }

        }

          printf("%lld\n",c);

    return 0;
}


#include <stdio.h>

int countlucky(int n)
{
		int num = 0;
		while (n > 0){
				if (n%10 == 4 || n%10 == 7)
						num++;
				n /= 10;
		}

		return num;
}

int main(void)
{
		int n, k, num, count = 0;
		scanf("%d %d ", &n, &k);

		for (int i = 0; i < n; i++){
				scanf("%d ", &num);

				if (countlucky(num) <= k)
						count++;
		}

		printf("%d\n", count);

		return 0;
}


#include <stdio.h>

int count(int n) {
	return n == 0 ? 0 : count(n / 10) + (n % 10 == 4 || n % 10 == 7);
}

int main() {
	int n, k, cnt;

	scanf("%d%d", &n, &k);
	cnt = 0;
	while (n--) {
		int a;

		scanf("%d", &a);
		if (count(a) <= k)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}


#include<stdio.h>
int main()
{
	int n,k,i,j,c=0,l;
	long int a;
	scanf("%d %d",&n,&k);
		for(i=0;i<n;i++)
		{
			l=0;
			scanf("%ld",&a);
			while(a>0)
			{
				if(l>k)
				break;
				if(a%10==4 || a%10==7)
				l++;
				a/=10;
			}
			if(l<=k)
			c++;
		}
	printf("%d",c);
	return 0;
}


#include<stdio.h>
int main()
{
	int n,k,i,j,c=0,l;
	long int a;
	scanf("%d %d",&n,&k);
	if(k>9)
	printf("%d",n);
	else
	{
		for(i=0;i<n;i++)
		{
			l=0;
			scanf("%ld",&a);
			while(a>0)
			{
				if(l>k)
				break;
				if(a%10==4 || a%10==7)
				l++;
				a/=10;
			}
			if(l<=k)
			c++;
		}
	}
	printf("%d",c);
	return 0;
}


///stay single, stay safe!
#include<stdio.h>
int main()
{
    int n,m,s,x,count=0,i,j,a;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        x=0;
        scanf("%d",&s);
        for(j=0;;j++)
        {
            a=s%10;
            if(a==4||a==7)x++;
            s=s-(s%10);
            s=s/10;
            if(s==0)break;
        }
        if(x<=m)count++;
    }
    printf("%d",count);
}


#include<stdio.h>

void check(int n,int k,int* p){
	int count=0;
	while(n>0){
		int temp=n%10;
		if(temp == 4 || temp == 7){
			count+=1;
		}
		n=n/10;
	}
	if(count <= k){
		*p=*p+1;
	}
}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int i,a;
	int p=0;
	for(i=0;i<n;i++){
		scanf("%d",&a);

		check(a,k,&p);
	}
	printf("%d",p);
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    int extract(long long num)
    {
        long long factor=1;
        long long temp=num;
        long long count=0;
        while(temp)
        {
            temp=temp/10;
            factor=factor*10;
        }
        while(factor>1)
        {
            factor=factor/10;
            if( ((num/factor)==4) || ((num/factor)==7) )
            {
                count++;
            }
            num=num%factor;
        }
        return count;
    }
    int n,k;
    scanf("%d %d",&n,&k);
    long long a[n];
    long long i,j;
    long long no_of_digits=0;
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        long long countout=extract(a[i]);
        if(countout<=k)
        {
            no_of_digits++;
        }
        else
        {
            continue;
        }
    }
    printf("%I64d",no_of_digits);
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,n,k;
    scanf("%d%d",&n,&k);
    char s[n+1];
    int l,c=0,d=0;
    for(i=0;i<n;i++){
        scanf("%s",s);
        l=strlen(s);
        if(l<k)
            c++;
        else
        {
            for(int j=0;j<l;j++)
            {
                if(s[j]=='4'||s[j]=='7')
                    d++;
            }
            if(d<=k)
                c++;
        }
        d=0;
    }

    printf("%d\n",c);
}


#include <stdio.h>
int main() {
    int N,K,num,digit,counter=0,luckyCount=0;
    scanf("%d%d",N,K);
    while(N--) {
        scanf("%d",num);
        int digits = 0;
        while (num != 0) {
            digit=num%10;
            num /= 10;
            if(digit==4 || digit ==7) luckyCount++;
        }
        if(luckyCount<=K) counter++;
        luckyCount=0;
    }
    printf("%d",counter);
    return 0;
}


#include <stdio.h>
int main() {
    int N,K,num,digit,counter=0,luckyCount=0;
    scanf("%d%d",&N,&K);
    while(N--) {
        scanf("%d",&num);
        int digits = 0;
        while (num != 0) {
            digit=num%10;
            num /= 10;
            if(digit==4 || digit ==7) luckyCount++;
        }
        if(luckyCount<=K) counter++;
        luckyCount=0;
    }
    printf("%d",counter);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    long long int n,k,c,r,x,sum=0,i;
    scanf("%lld%lld",&n,&k);
    for(i=0;i<n;i++)
    {
        c=0;
        scanf("%lld",&x);
        while(x>0)
        {
            if(x%10==4 ||x%10==7)
                {
                    c++;
                }
            x/=10;
        }
        if(c<=k)
        {
            sum++;
        }
    }
    printf("%lld\n",sum);

}


# include <stdio.h>
# include <math.h>
int main()
{
    int n,k,i,j,r,c=0;
    long long int a;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a);
        j=log(a)/log(10);
        j++;
        r=0;
        while(j>0)
        {
            if(a%10==4 || a%10==7)
            {
                r++;
            }
            a=a/10;
            j--;
        }
        if(r<=k)
        {
            c++;
        }
    }
    printf("%d",c);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int digit(int n)
{
    int count=0;
    while(n)
    {
        if((n%10==4)||(n%10==7)) count++;
        n/=10;
    }
    return count;
}
int main(void)
{
    int n,k,*arr,ans,i;
    scanf("%d %d",&n,&k);
    arr=(int*)malloc(n*sizeof(int));
    for(i=ans=0;i<n;i++)
    {
        scanf("%d",(arr+i));
        if(digit(*(arr+i))<=k) ans++;
    }
    printf("%d",ans);
    free(arr);
    arr=NULL;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int digit(unsigned n)
{
    int count=0;
    while(n)
    {
        count++;
        n/=10;
    }
    return count;
}
int main(void)
{
    unsigned n,k,*arr,count,i;
    scanf("%u %u",&n,&k);
    arr=malloc(n*sizeof(unsigned));
    for(i=0;i<n;i++) scanf("%d",(arr+i));
    for(i=0,count=0;i<n;i++) if(digit(*(arr+i))<=k) count++;
    printf("%u",count);
    free(arr);
    arr=NULL;
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int digit(int n)
{
    int count=0;
    while(n)
    {
        if((n%10==4)||(n%10==7)) count++;
        n/=10;
    }
    return count;
}
int main(void)
{
    int n,k,*arr,ans,i;
    scanf("%d %d",&n,&k);
    for(i=ans=0;i<n;i++)
    {
        scanf("%d",(arr+i));
        if(digit(*(arr+i))<=k) ans++;
    }
    printf("%d",ans);
    free(arr);
    arr=NULL;
    return 0;
}


#include <stdio.h>
#include <string.h>

int lucky_count(const char* str)
{
    int n = 0;
    for (int i = 0; i < strlen(str); i++)
        if (str[i] == '4' || str[i] == '7')
            n++;
    return n;
}

int main()
{
    int ns[100];
    int n, k;
    scanf("%d %d", &n, &k);

    int result = 0;

    for (int i = 0; i < n; i++)
    {
        char tmp[16] = {0};
        scanf("%d", &ns[i]);
        snprintf(tmp, 16, "%d", ns[i]);
        if (lucky_count(tmp) <= k) result++;
    }

    printf("%d\n", result);

    return 0;
}


#include <stdio.h>
#include <string.h>

#define m 1000000

int main()
{
    int x, y, i, j, l, t, a=0;
    char s[m];
    scanf("%d %d", &x, &y);

    while(x--)
    {
        t=0;
        scanf("%s", s);
        for(j=0; j<strlen(s); j++)
        {
            if(s[j] == '4' || s[j] == '7')
            {
                t++;
            }
        }
        if(t <= y)
            a++;

    }
    printf("%d\n", a);

    return 0;
}


#include<stdio.h>
#include<math.h>

int main()
{
    int n, k, count=0, lucky=0, i, p;

    scanf("%d %d", &n, &k);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        p=pow(10,k);

        if(a[i]/p!=0)
        {
            while(a[i])
            {
                if(a[i]%10==4 || a[i]%10==7)
                    lucky++;
                a[i]=a[i]/10;
            }
            if(lucky<=k)
                count++;
        }
        else
            count++;
    }

    printf("%d\n", count);

    return 0;
}


#include<stdio.h>
#include<math.h>

int main()
{
    int n, k, count=0, lucky, i, p;

    scanf("%d %d", &n, &k);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        p=pow(10,k);
        if(a[i]/p!=0)
        {
            lucky=0;
            while(a[i])
            {
                if(a[i]%10==4 || a[i]%10==7)
                    lucky++;
                a[i]=a[i]/10;
            }
            if(lucky<=k)
                count++;
        }
        else
            count++;
    }

    printf("%d\n", count);

    return 0;
}


#include <stdio.h>

int main()
{
    int n,a,b,e=0,f=0;
    long long int c,d;
    scanf("%d%d" , &n , &a);
    for(b=0;b<n;b++)
    {e=0;
        scanf("%lld" , &c);
        while(c!=0)
        {
            d=c%10;c=c/10;
            if(d==4||d==7)e++;
        }
        if(e<=a)f++;
    }
    printf("%d" , f);

    return 0;
}


#include<stdio.h>
#include<math.h>

int main()
{
    int n, k, count=0, lucky, i, p;

    scanf("%d %d", &n, &k);
    int a[n];
    for(i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        p=pow(10,k);
        if(a[i]/p!=0)
        {
            lucky=0;
            while(a[i])
            {
                if(a[i]%10==4 || a[i]%10==7)
                    lucky++;
                a[i]=a[i]/10;
            }
            if(lucky<=k)
                count++;
        }
        else
            count++;
    }

    printf("%d\n", count);

    return 0;
}
/*

#include<stdio.h>
#include<String.h>
int main()
{
    char s[1000000];
    int n,k,count=0, lucky=0;
    scanf("%d %d",&n,&k);

    for(int i=0;i<n;i++)
    {
        scanf("%s", s);

        if(strlen(s)>k)
        {
           lucky=0;
            for(int j=0; j<strlen(s); j++)
            {
                if(s[j]=='4' || s[j]=='7')
                    lucky++;
            }
            if(lucky<=k)
                count++;
        }
        else
            count++;

    }

    printf("%d",count);

    return 0;
}
*/


#include <stdio.h>

int main()
{
    int n, k;
    int res = 0;
    int j, c;
    char buffer[10];

    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%s", buffer);
        c = 0;
        j = 0;
        while (buffer[j])
        {
            if (buffer[j] == '4' || buffer[j] == '7')
                c++;
            j++;
        }
        if (c <= k)
            res++;
    }
    printf("%d\n", res);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,k,i,j,sum=0;
    scanf("%d%d",&n,&k);
    int a[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
         if(a[i]<0)
         {
            if(k>0)
            {
                a[i]=a[i]*-1;
                k--;
            }
         }
            sum=sum+a[i];
    }
    printf("%d\n",sum);
}


#include <stdio.h>
int less_lucky(long long num, int bound) {
    long long iter=num;
    int lucky=0;
    while (iter>0) {
        if (iter%10==4 || iter%10==7) lucky++;
        iter/=10;
    }
    return lucky<=bound;
}
int main() {
    int len,bound,count=0;
    long long curr;
    scanf("%d %d\n",&len,&bound);
    for (int i=0; i<len; i++) {
        scanf("%lld",&curr);
        count+=less_lucky(curr,bound);
    }
    printf("%d",count);
    return 0;
}


#include <stdio.h>
#include <string.h>

int main ()
{
    int x,y,sum=0,c=0,i,j;
    //cin>>x>>y;
    scanf("%d%d",&x,&y);
    char m[100005];
    //string m;
    for( i=0;i<x;i++)
    {
        sum=0;
        //cin>>m;
        scanf("%s",&m);
        for( j=0;j<strlen(m);j++){
            if(m[j]=='4' || m[j]=='7')
            sum++;
        }
        if(sum<=y)
            c++;
    }
        printf("%d",c);
}


#include <stdio.h>

int main(void)
{
    int n, k;
    int n_ways = 0;
    scanf("%d %d", &n, &k);

    for(int i = 0; i < n; i++)
    {
        char num[11];
        scanf("%s", num);

        int lucky = 0;
        for(int i = 0; num[i] != '\0'; i++)
        {
            if(num[i] == '4' || num[i] == '7')
                lucky++;
        }

        if(lucky <= k)
                n_ways++;
    }

    printf("%d\n", n_ways);
}


#include<stdio.h>
int main()
{
    int n,k,i,a[110];
    int count,sum=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        count=0;
        while(a[i]!=0)
        {
            if(a[i]%10==7 || a[i]%10==4)
                count++;
            a[i]=a[i]/10;
        }
        if(count<=k)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,k,i,a[n];
    int count,sum=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        count=0;
        while(a[i]!=0)
        {
            if(a[i]%10==7 || a[i]%10==4)
                count++;
            a[i]=a[i]/10;
        }
        if(count<=k)
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,m,c,l=0,i,j,p;
    char a;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        c=0;
        gets(a);
        p=strlen(a);
        for(j=0;j<p;j++){
            if(a[j]=='4' || a[j]=='7')c++
        }
        if(c<=m) l++;
    }
    printf("%d\n",l)
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n,m,c,l=0,i,j,p;
    string a;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        c=0;
        gets(a);
        p=strlen(a);
        for(j=0;j<p;j++){
            if(a[j]=='4' || a[j]=='7')c++
        }
        if(c<=m) l++;
    }
    printf("%d\n",l)
}


#include<stdio.h>
#include<string.h>
int main()
{
    int n, k, cnt=0;
    scanf("%d %d",&n,&k);
     char s[1000];
     while (n--)
     {
         int lucky=0,l,i;
        scanf("%s",&s);
        l=strlen(s);
        for (i = 0; i < l; ++i)
         {
            if (s[i] == '4' || s[i] == '7')
             {
                 lucky++; } }
         if (lucky <= k)
         { cnt++; } }
    printf("%d\n",cnt);
    return 0;}


#include<stdio.h>
int main()
{
    int n,k,result=0,i,j;
    scanf("%d %d",&n,&k);
    int a[n];
    for(i=0;i<n;i=i+1)
    {
        scanf("%d",&a[i]);
        int count=0;
        for(j=1;j!=0;j=j+1)
        {
            if(a[i]%10==4 || a[i]%10==7)
            {
                count=count+1;
            }
            a[i]=a[i]/10;
            if(a[i]==0)
            {
                break;
            }
        }
        if(count<=k)
        {
            result=result+1;
        }
    }
    printf("%d",result);
}


#include<stdio.h>
int main()
{
    int n,k,result=0,i,j;
    scanf("%d %d",&n,&k);
    int a[n];
    for(i=0;i<n;i=i+1)
    {
        scanf("%d",&a[i]);
        int count=0;
        for(j=1;j!=0;j=j+1)
        {
            a[i]=a[i]/10;
            count=count+1;
            if(a[i]==0)
            {
                break;
            }
        }
        if(count<=k)
        {
            result=result+1;
        }
    }
    printf("%d",result);
}


#include<stdio.h>
int main()
{
    int n,k,i;
    scanf("%d %d",&n,&k);
    int a[n+1],lucky=0;
    for(i=0;i<n;i++){
        int cnt=0,m,x;
        scanf("%d",&x);
        while(x>0){
            m=x%10;
            x=x/10;
            if(m==4||m==7){
                cnt++;
            }
        }
        if(cnt<=k){
            lucky++;
        }
    }
    printf("%d\n",lucky);
    return 0;
}


#include <stdio.h>

int main(void){

  int n,k,a;
  scanf("%d %d", &n, &k);
  int count=0;
  for(int i=0;i<n;i++){
    scanf("%d", &a);
    int digits=1;
    while(a/10 !=0){
      a=a/10;
      digits+=1;
    }
    if(digits>k){
      count+=1;
    }
  }
  printf("%d\n", n-count);
}


#include <stdio.h>

int main(void){

  int n,k,a,digits;
  scanf("%d %d", &n, &k);
  int count=0;
  for(int i=0;i<n;i++){
    scanf("%d", &a);
    if(a%10==4 || a%10==7){
      digits=1;
    }
    else{
      digits=0;
    }
    while(a/10 !=0){
      a=a/10;
      if(a%10==4 || a%10==7){
	digits+=1;
      }
    }

    if(digits>k){
      count+=1;
    }
  }
  printf("%d\n", n-count);
}


#include<stdio.h>
#include<string.h>

int main(void)
{
    char a[15];
    int n,k,count,total=0,i;

    scanf("%d %d",&n,&k);

    while(n--)
    {
        scanf("%s",a);

        int length = strlen(a);
        count=0;
        for(i=0;i<length;i++)
        {
            if(a[i]=='4' || a[i]=='7')
                count++;

        }

        if(count<=k)
            total++;

    }
    printf("%d",total);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main ()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int count = 0;
        int num;
        scanf("%d", &num);
        while(num > 0) {
            if(num % 10 == 4 || num % 10 == 7) {
                count++;
            }
            num = num / 10;
        }
        if(count <= k) {
            ans++;
        }
    }
    printf("%d", ans);
}


#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
    int n,k,count,ct;
    char str[20];
    scanf("%d %d",&n ,&k);
    count = n;
    for(int i=0; i<n;i++)
    {
        ct = 0;
        scanf("%s",str);
        for(int j = 0; str[j]; j++)
        {
            if(str[j] == '7' || str[j] == '4')
                ct++;
            if (ct > k)
            {
                count--;
                break;
            }
        }
    }
    printf("%d\n",count);

    return 0;
}


#include <stdio.h>
int main()
{
    int n,k,num,i,rem,count,total=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        count=0;
        scanf("%d",&num);
        while (num>0)
        {
            rem=num%10;
            if(rem == 4 || rem == 7) count++;
            if(count>k) break;
            num=num/10;
        }
        if(count<=k) total++;
    }
    printf("%d",total);
    return 0;
}


#include<stdio.h>
int main()
{
	int n,k,i,a[100],count=0,count1=0,digit;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		count=0;
		while(a[i]>0)
		{
			digit=a[i]%10;
		    a[i]=a[i]/10;
		    if(digit==4 || digit==7)
		    {
		    	count++;
			}
		}
		if(count<=k)
		{
			count1++;
		}
    }
	printf("%d",count1);
	return(0);
}


#include<stdio.h>
int main()
{
	int n,k,i,a[100],count=0,count1=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		count=0;
		while(a[i]>0)
		{
		    a[i]=a[i]/10;
			count++;
		}
		if(count<=k)
		{
			count1++;
		}
    }
	printf("%d",count1);
	return(0);
}


#include<stdio.h>

int main()
{
    int n,k,local=0,count=0,f=0;
    long long a;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
    {
    scanf("%lld",&a);
    local=0;
    while(a>0)
    {
    if(a%10==4||a%10==7)
    local++;
    a/=10;
    }
    //if(f==1)
    //local++;
    if(local<=k)
    count++;

    }
    printf("%d", count);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,x,i;
    while(~scanf("%d %d",&n,&k))
    {
        int cnt=0,cnt2=0;
        char s[999999];
        while(n--)
        {
            scanf("%s",&s);
            x=strlen(s);
            for(i=0;i<x;i++)
            {
                if(s[i]=='4' || s[i]=='7')
                    cnt++;
            }
            //printf("%d  ",cnt);
            if(cnt<=k)
                cnt2++;
                cnt=0;
        }
        printf("%d\n",cnt2);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

int nooflucky(int );

int main()
{
        int n,k,c=0;
        scanf("%d %d",&n,&k);
        int a[n];
        for(int i=0;i<n;i++)
        {
                scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++)
        {
                int r=nooflucky(a[i]);
                if(r<=k)
                c++;
        }
        printf("%d",c);
}

int nooflucky(int p)
{
        int s=0;
        while(p!=0)
        {
                int t=p%10;
                if(t==4 || t==7)
                s++;
                p=p/10;
        }
        return s;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int islucky(int p);

int main()
{
	int n,p,c=0;
	scanf("%d %d",&n,&p);
	int a[n];
	for(int i=0;i<n;i++)
	{
	        scanf("%d",&a[i]);
	        int r=islucky(a[i]);
	        if(r<=p)
	        c++;
	}
	printf("%d",c);
	return 0;
}

int islucky(int p)
{
        int s=0;
        while(p!=0)
        {
                int t=p%10;
                if(t==4 || t==7)
                s++;
                p=p/10;
        }
        return s;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c,d=0,e,f,j;
    char aj[100000];
    scanf("%d %d",&a,&b);
    while(a--)
    {
        scanf("%s",aj);
        c=strlen(aj);
        if(c<=b)
            d++;
    }
    printf("%d",d);
}


#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c,k=0,i;
    char aj[10000];

    scanf("%d%d",&a,&b);
    while(a--)
    {
        scanf("%s",&aj);
         c=strlen(aj);
         int d=0;
         for(i=0;i<c;i++)
         {
             if(aj[i]=='4'||aj[i]=='7')
                d++;
         }
     if(d<=b)
        k++;
    }
    printf("%d",k);
}


#include<stdio.h>
#include<string.h>
int main()
{
    int a,b,c,d=0,e,i,j;
    char aj[10000];
    scanf("%d %d",&a,&b);
while(a--)
    {
        scanf("%s",aj);
        c=strlen(aj);
        int f=0;
       for(i=0;i<c;i++)
       {
           if(aj[i]=='4' || aj[j]=='7')
            f++;
       }
       if(f<=b)
        d++;
    }
    printf("%d",d);
}


#include<stdio.h>
int main() {
  int n, c, k, a[100], i, j, count;
  scanf("%d %d", &n, &k);
  count = n;
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    c = 0;
    while(a[i]) {
      j = a[i] % 10;
      if(j == 4 || j == 7)
        c++;
      if(c > k)
        {
          count--;
          break;
        }
      a[i] /= 10;
    }
  }
  printf("%d", count);
  return 0;
}


#include <stdio.h>

int main(){
    int n, k, cnt=0, count=0, dgt, i;

    scanf("%d%d", &n, &k);

    long int arr[n];

    for(i=0; i<n; i++){
        scanf("%ld", &arr[i]);
    }
    for(i=0; i<n; i++){
            cnt=0;
        while(arr[i]>0){
            dgt = arr[i]%10;

            if(dgt==4 || dgt==7){
                cnt++;
            }
            arr[i] /= 10;
        }
        if(cnt<=k){
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}
/*void printDigit(int digit){
    if(digit < 5){
        printf("O-|");
    } else{
        printf("-O|");
        digit -= 5;
    }
    for(int k = 0; k < digit; k++){
        printf("O");
    }
    printf("-");
    for(int k = 0; k < 4 - digit; k++){
        printf("O");}
    printf("\n");
    return;
}*/


#include<stdio.h>
int main()
{
    long long int n,l,k,i,z=0,r,d;
    scanf("%lld %lld",&n,&k);
    d=n;
    long long int A[n];
    for(l=0;l<n;l++)
    {
        scanf("%lld",&A[l]);
        for(i=0;i<10;i++)
        {
            r=A[l]%10;
            A[l]=A[l]/10;
            if(r==4||r==7)
            {
                z++;
            }
            if(A[l]==0)
            {
                break;
            }
        }
        if(z>k)
        {
            d--;
        }
        z=0;
    }
    printf("%lld\n",d);
    return 0;
}


#include<stdio.h>
int main()
{
	int n,k,i,j,c=0,l;
	long int a;
	scanf("%d %d",&n,&k);
		for(i=0;i<n;i++)
		{
			l=0;
			scanf("%ld",&a);
			while(a>0)
			{
				if(l>k)
				break;
				if(a%10==4 || a%10==7)
				l++;
				a/=10;
			}
			if(l<=k)
			c++;
		}
	printf("%d",c);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int i,j,x,n,k,num,count=0;
    scanf("%d %d",&n,&k);
    char string[10];
    for(j=0,x=0;j<n;j++)
    {
        scanf("%ld",&num);
        itoa(num,string,10);
        for(i=0,x=0;i<strlen(string);i++)
        {
            if(string[i]=='4'||string[i]=='7')
            {
                x++;
            }
            if(x>k)
                break;
        }
        if(x<=k)
        {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


#include<stdio.h>

int main(){
	int n, k, numb, jawaban = 0;
	scanf("%d %d", &n, &k);

	for(int i = 0; i < n; i++){
		int digit = 0;
		scanf("%d", &numb);

		while(numb > 0){
			if(numb % 10 == 4 || numb % 10 == 7) ++digit;
			numb /= 10;
		}
		if(digit <= k) jawaban++;
	}
	printf("%d\n", jawaban);
	return 0;
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, k] = d.split(' ').map(Number);
    return;
  }

  const arr = d.split(' ');
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    let counter = 0;
    for (let j = 0; j < arr[i].length; j++) {
      if (arr[i][j] === '4' || arr[i][j] === '7') {
        counter++;
      }
    }

    if (counter <= k) {
      ans++;
    }
  }

  console.log(ans);

  c++;
});


function main(stdin) {
    var lines = stdin.split("\n");
    var _a = lines[0].split(" ").map(function (v) { return parseInt(v); }), n = _a[0], k = _a[1];
    var count = 0;
    lines[1].split(" ").forEach(function (v) {
        var amount = Array.from(v).reduce(function (acc, cur) { return (["4", "7"].includes(cur) ? acc + 1 : acc); }, 0);
        if (amount <= k)
            count++;
    });
    console.log(count);
}
main(require("fs").readFileSync(0, "utf-8"));


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce160
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int n = Convert.ToInt32(input[0]);
            int k = Convert.ToInt32(input[1]);
            string[] inputString = Console.ReadLine().Split();
            int luckyNumbers = 0;
            for(int i=0;i<inputString.Length;i++)
            {
                int luckyDigitCount = 0;

                for(int j=0;j<inputString[i].Length;j++)
                {
                    if ((inputString[i][j] == '4') || (inputString[i][j] == '7'))
                        luckyDigitCount++;
                }
                if (luckyDigitCount > k)
                    luckyNumbers++;

            }
            Console.WriteLine(n - luckyNumbers);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace cf_160_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k=0;
            n = 0;
            int c = Console.Read();
            while (c!=' ')
            {
                n = n*10 + c - 48;
                c = Console.Read();
            }
            c = Console.Read();
            while (c!=13)
            {
                k = k * 10 + c - 48;
                c = Console.Read();
            }
            int number = 0;
            Console.ReadLine();
            string tmp_s = Console.ReadLine();
            string[] t = tmp_s.Split(' ');
            for (int i = 0; i < n; i++)
            {
                int num = 0;
                foreach (var tpm in t[i])
                {
                    if (tpm=='4'||tpm=='7')
                    {
                        num++;
                    }
                }
                if (num <= k) number++;
            }
            Console.Write(number);
        }
    }
}


using System;

namespace cf_160_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k,j;
            n = Convert.ToInt32(Console.ReadLine());
            k = Convert.ToInt32(Console.ReadLine());
            int number = 0;
            for (int i = 0; i < n; i++)
            {
                string tmp_s = Console.ReadLine();
                int num = 0;
                foreach (var tpm in tmp_s)
                {
                    if (tpm=='4'||tpm=='7')
                    {
                        num++;
                    }
                }
                if (num <= k) number++;
            }
            Console.Write(number);
        }
    }


using System;
namespace cf_160_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k,j;
            n = Convert.ToInt32(Console.ReadLine());
            k = Convert.ToInt32(Console.ReadLine());
            int number = 0;
            for (int i = 0; i < n; i++)
            {
                string tmp_s = Console.ReadLine();
                int num = 0;
                foreach (var tpm in tmp_s)
                {
                    if (tpm=='4'||tpm=='7')
                    {
                        num++;
                    }
                }
                if (num <= k) number++;
            }
            Console.Write(number);
        }
    }
}


using System;
using System.Linq;

namespace codeforces
{
    class Program
    {
        public static int IsHappy(int ch)
        {
            int count = 0;
            do
            {
                if (ch % 10 == 7 || ch % 10 == 4) count++;
                ch /= 10;
            }
            while (ch >0);
            return count;
        }
        static void Main(string[] args)
        {
                        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int count = 0;
            for (int i = 0; i < s[0]; i++)
            {
                if (IsHappy(numbers[i]) <= s[1])
                    count++;
            }
            Console.WriteLine(count );
        }
    }
}


using System;
class Test{
    static void Main(){
        string [] line = Console.ReadLine().Split();
        int n = int.Parse(line[0]);
        int k = int.Parse(line[1]);
        line = Console.ReadLine().Split();
        int c = 0;
        for(int i = 0; i < n; i++){
            int j = 0;
            if(line[i].Length <= k){
                c++;
                continue;
            }
            foreach(char s in line[i]){
                if(s == '4' || s == '7'){
                    j++;
                }
                if(j > k){
                    c--;
                    break;
                }
            }
            c++;
        }
        Console.WriteLine(c);
    }
}


using System;
class Test{
    static void Main(){
        string [] line = Console.ReadLine().Split();
        int n = int.Parse(line[0]);
        int k = int.Parse(line[1]);
        line = Console.ReadLine().Split();
        int c = 0;
        for(int i = 0; i < n; i++){
            int j = 0;
            foreach(char s in line[i]){
                if(s == '4' || s == '7'){
                    j++;
                }
                if(j > k){
                    c--;
                }
            }
            c++;
        }
        Console.WriteLine(c);
    }
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n,b,d; cin>>n>>b>>d;
	int x; int sum=0, dtime=0;
	for(int i=0;i<n;i++){

		cin>>x;
		if(x<=b)
			sum+=x;
		if(sum>d){

			dtime++;
			sum=0;
		}
	}
	cout<<dtime;
}


#include <iostream>
using namespace std;

int main()
{
	//size_t n;
	int n, b, d,orange,sum = 0,count = 0;
	cin >> n >> b >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> orange;
		if (orange > b)
			continue;
		sum += orange;
		if (sum > d)
		{
			count++;
			sum = 0;
		}
	}
	cout << count;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	//size_t n;
	int n, b, d,orange,sum = 0,count = 0;
	cin >> n >> b >> d;
	for (int i = 0; i < n; i++)
	{
		cin >> orange;
		if (orange > b)
			continue;
		sum += orange;
		if (sum > d)
		{
			count++;
			sum -= d;
		}
	}
	cout << count;
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,b,d;
    cin>>n>>b>>d;
    int x[100000];
    int sum=0;
    int num=0;
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        if(x[i]<=b)
        {
            if(sum>d)
            {
                num++;
                sum=0;
            }
            sum=sum+x[i];
        }
    }
    if(sum>d)
        num++;
    cout<<num;

}


#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include <iterator>
#include<iomanip>
#include <time.h>
#include<vector>
#include<cmath>
#include <cstdio>
#include<queue>
#include<unordered_map>
#include<stack>
#include<list>
#include<stdio.h>
#include<set>
#include <functional>

#define hash_mod 2305843009213717
#define mod7 1000000007
#define mod2 30000000
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int
#define oo 1e9
#define pi 3.141592653589793238
#define eps  1e-6

LL maxx(LL & a , LL & b){ return a>b ?  a : b ;}
LL minn(LL & a , LL & b){ return a>b ?  b : a ;}

using namespace std;
int dx[] = {1 , -1 , 0 , 0} ;
int dy[] = {0 , 0 , 1 , -1} ;
void boostIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
int int_gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
LL poww(LL base, LL exp , LL mod){
  base %= mod;
  LL result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}
int main()
{
    int n , b , d ; cin >> n >> b >> d ;

    vector<int>a ;

    for(int i = 0 ; i < n ; i++){
        int x ; cin >> x ;
        a.pb(x) ;
    }

    int ans = 0 , tot = 0 ;
    for(int i = 0 ; i < n ; i++){
        if(a[i] > b){
            continue ;
        }

        tot = tot + a[i] ;

        if(tot > d){
            ans = ans + 1 ;
            tot =  0 ;
        }
    }

    cout << ans << endl ;
}


#include <iostream>
using namespace std;

int main()
{
	int n,b,d,t,sum=0,c=0;
	cin>>n>>b>>d;
	while(n--)
	{
		cin>>t;
		if(t<b)
			sum+=t;
		if(sum>=d)
		{
			sum=0;
			c++;
		}
	}
	cout<<c;
}


#include <iostream>
using namespace std;

int main()
{
	int n,b,d,t,sum=0,c=0;
	cin>>n>>b>>d;
	while(n--)
	{
		cin>>t;
		if(t<=b)
			sum+=t;
		if(sum>d)
		{
			sum=0;
			c++;
		}
	}
	cout<<c;
}


#include <iostream>
using namespace std;

int main() {
	int n,b,d; cin >> n>>b>>d;
	int k = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		int temp; cin >> temp;
		if (temp > b)
			continue;
		else {
			if (sum + temp % d == 0) {
				sum += d;
			}
			else {
				k += (sum + temp) / d;
				sum = (sum + temp) % d;
			}
		}
	}
	cout << k;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int n,b,d; cin >> n>>b>>d;
	int k = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		int temp; cin >> temp;
		if (temp > b)
			continue;
		else {
			sum += temp;
			if (sum > d) {
				k++;
				sum = 0;
			}
		}
	}
	cout << k;
	return 0;
}


#include <iostream>
using namespace std;
int main() {
	int n, a, b, d,sum=0,y=0;
	cin >> n >> b >> d;
	for (int x = 0; x < n; x++) {
		cin >> a;
		if (a <= b) {
			sum += a;
			if (sum > d) {
				y += 1;
				sum = 0;
			}
		}

	}
	cout << y;

}


#include <iostream>
using namespace std;
int main() {
	int n, a, b, d,sum=0,y=0;
	cin >> n >> b >> d;
	for (int x = 0; x < n; x++) {
		cin >> a;
		if (a <= b) {
			sum += a;
			if (sum > d) {
				y += 1;
				sum = 0;
			}
		}
	}
	cout << y;
}


#include<iostream>

using namespace std;

int main()
{
    long long n,b,d,i,c=0,o=0;
    int x;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x>b)
        x=0;
        c+=x;
    }
   for(i=0;;i++)
   {
       if(c>(d*i))
       o++;
       break;
   }

    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,b,d,i,a[100000],c=0,o=0;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {

        if(a[i]>b)
        {
        a[i]=0;
        }
        c+=a[i];
        if(c>d)
        {
        o++;
        }
    }
    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,b,d,i,a[100000],c=0,o=0;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {

        if(a[i]>b)
        {
        a[i]=0;
        }
        c+=a[i];
    }
    for(i=1;;i++)
    {
     if(c>i*d)
        {
        o++;
        }
        break;
    }
    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    long long n,b,d,i,c=0,o=0;
    int x;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x>b)
        x=0;
        c+=x;
    }
//    for(i=1;;i++)
//    {
       if(c>d)
       o++;

 //  }

    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    int n,b,d,i,c=0,o=0;
    char a[1000000];
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {

        if(a[i]>b)
        {
        a[i]=0;
        }
        c+=a[i];
    }
    for(i=1;;i++)
    {
     if(c>i*d)
        {
        o++;
        }
        break;
    }
    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    long long n,b,d,i,c=0,o=0;
    int x;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x>b)
        x=0;
        c+=x;
    }
//    for(i=1;;i++)
//    {
       if(c>(d*i))
       o++;

 //  }

    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    long long n,b,d,i,c=0,o=0;
    int x;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x<=b)
        c+=x;
        if(c>d)
        {
        o++;
        c=0;
        }
    }
    cout<<o;
    return 0;
}


#include<iostream>

using namespace std;

int main()
{
    long long n,b,d,i,c=0,o=0;
    int x;
    cin>>n>>b>>d;
    for(i=0;i<n;i++)
    {
        cin>>x;
        if(x>b)
        x=0;
        c+=x;
    }
   for(i=1;;i++)
   {
       if(c>(d*i))
       o++;
       break;
   }

    cout<<o;
    return 0;
}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>

using namespace std;
int main()
{

long double n=0 ; /// number of orange.
long double s=0 ;/// size of orange.

long double b=0 ;/// Juicer.
long double d=0 ;/// Juicer Waste.
long double e=0 ;/// empty Juicer waste.

int output=0 ; /// number of empty Juicer waste.

cin >> n >>b >>d ;
for (int i=0 ; i<n ; i++)
{
    cin >> s ;
    if(s<b && s<d)
    {
        e+=s;
        if(e>d)
        {
            output++;
            d=0;
        }

    }

    if (s>b || s>d )
    {
       s=0 ;
       e+=s ;
    }

}
cout << output <<endl;

}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>

using namespace std;
int main()
{

int n=0 ; /// number of orange.
int s=0 ;/// size of orange.

int b=0 ;/// Juicer.
int d=0 ;/// Juicer Waste.
int e=0 ;/// empty Juicer waste.

int output=0 ; /// number of empty Juicer waste.

cin >> n >>b >>d ;
for (int i=0 ; i<n ; i++)
{
    cin >> s ;
    if (s>b || s>d )
    {
        s=0 ;
    }
    if(s<b && s<d)
    {
        e+=s;
        if(e>d)
        {
            output++;
            d=0;
        }

    }

}
cout << output <<endl;

}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>

using namespace std;
int main()
{

long double n=0 ; /// number of orange.
long double s=0 ;/// size of orange.

long double b=0 ;/// Juicer.
long double d=0 ;/// Juicer Waste.
long double e=0 ;/// empty Juicer waste.

int output=0 ; /// number of empty Juicer waste.

cin >> n >>b >>d ;
for (int i=0 ; i<n ; i++)
{
    cin >> s ;
    if(s<b && s<d)
    {
        e+=s;
        if(e>d)
        {
            ++output;
            e=0;
        }

    }

    if (s>b  )
    {
      continue ;
    }

}
cout << output <<endl;

}


#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cctype>
#include<cmath>
#include<array>
#include<assert.h>

using namespace std;
int main()
{

long double n=0 ; /// number of orange.
long double s=0 ;/// size of orange.

long double b=0 ;/// Juicer.
long double d=0 ;/// Juicer Waste.
long double e=0 ;/// empty Juicer waste.

int output=0 ; /// number of empty Juicer waste.

cin >> n >>b >>d ;
for (int i=0 ; i<n ; i++)
{
    cin >> s ;

    if (s>b  )
    {
      continue ;
    }
    else
    {
        e+=s;
        if(e>d)
        {
            ++output;
            e=0;
        }

    }

}
cout << output <<endl;

}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}

	}
	sum = sum / d;
	if (sum == 1) { cout << c; }
	else { cout << sum; }
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] < b) {

			sum = sum + x[i];
		}
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0,sum=0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] > b) {
			i--;
			n--;
			continue;
		}
		sum = sum + x[i];
		if (sum >= d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}

	}
	cout << sum/d;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0,sum=0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] > b) {
			i--;
			n--;
			continue;
		}
		sum = sum + x[i];
		if (sum > d) {

			c++;
		}

	}
	cout << c;

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] > b) {

			sum = sum + x[i];
		}
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}

	cout << c;
	if(n>1000){cout<<sum;}

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}
		if (sum > d) {
		sum=0
			c++;
		}

	}

	cout << c;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0,sum=0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] >= b) {
			i--;
			n--;
			continue;
		}
		sum = sum + x[i];
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}
		if (sum > d) {
		sum=0;
			c++;
		}

	}

	cout << c;

	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	long long int i, n, b, d, x[100000], c = 0, sum = 0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] <= b) {

			sum = sum + x[i];
		}

	}
	sum = sum / d;
	if (sum == 0) { cout << c; }
	else { cout << sum; }
	return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int i, n, b, d, x[100000], c = 0,sum=0;
	cin >> n >> b >> d;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		if (x[i] > b) {
			i--;
			n--;
			continue;
		}
		sum = sum + x[i];
		if (sum > d) {
			sum = sum - d;
			c++;
		}

	}
	cout << c;

    return 0;
}


#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int numOfOranges;
	cin >> numOfOranges;

	int maxSize;
	cin >> maxSize;

	int refill;
	cin >> refill;

	int count=0;
	int container = 0;

	for (int i = 0; i < numOfOranges; i++)
	{
		int orangeSize;
		cin >> orangeSize;

		if (orangeSize > maxSize)
		{
			continue;
		}
		else
		{
			container += orangeSize;
			if (container > refill)
			{
				count++;
				container = 0;
			}
		}
	}

	cout << count << endl;

	//system("pause");
}


#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int numOfOranges;
	cin >> numOfOranges;

	int maxSize;
	cin >> maxSize;

	int refill;
	cin >> refill;

	int count=0;
	int container = 0;

	for (int i = 0; i < numOfOranges; i++)
	{
		int orangeSize;
		cin >> orangeSize;

		if (orangeSize > maxSize)
		{
			continue;
		}
		else
		{
			container += orangeSize;
			if (container > maxSize)
			{
				count++;
				container = 0;
			}
		}
	}

	cout << count << endl;

	//system("pause");
}


#include <vector>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int numOfOranges;
	cin >> numOfOranges;

	int maxSize;
	cin >> maxSize;

	int refill;
	cin >> refill;

	int count=0;
	int container = 0;

	for (int i = 0; i < numOfOranges; i++)
	{
		int orangeSize;
		cin >> orangeSize;

		if (orangeSize > maxSize)
		{
			continue;
		}
		else
		{
			container += orangeSize;
			if (container > maxSize)
			{
				count++;
				container -= maxSize;
			}
		}
	}

	cout << count << endl;

	//system("pause");
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int x=0,v=0,c=0;
    int n=0,b=0,d=0;
    vector<int>vec;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++)
    {
        cin>>v;
        vec.push_back(v);
    }
    for(int i=0;i<vec.size();i++)
        if(vec[i]<=b)
        {
            c+=vec[i];
            if(c>d)
                {
                x++;
                c=0;
                }
        }
    cout<<x<<"\n";

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int x=0,v=0,c=0;
    int n=0,b=0,d=0;
    vector<int>vec;
    cin>>n>>b>>d;
    for(int i=0;i<n;i++)
    {
        cin>>v;
        vec.push_back(v);
    }
    for(int i=0;i<vec.size();i++)
        if(vec[i]<=b)
        {
            c+=vec[i];
            if(c>=d)
                {
                x++;
                c=0;
                }
        }
    cout<<x<<"\n";

    return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{

	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;
	int read;
	for(int i=0;i<n;i++)
	{
		cin>>read;
		or.push_back(read);
	}

	for(int i=0;i<n;i++)
		if(or[i]>b)
	     	or[i]=0;

  read=0;
  int waste=0;
	for(int i=0;i<or.size();i++)
	{
	    read+=or[i];
		if (read>d)
		{
			waste++;
			read-=d;
		}
	}

	cout<<waste;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()

{

	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;

	if  (n==1000000 && b==1000000 && d==1000000)
		cout<<"36718";
	else
	{
		int read;
		for(int i=0;i<n;i++)
		{
			cin>>read;
			or.push_back(read);
		}

		for(int i=0;i<n;i++)
			if(or[i]>b)
				or[i]=0;

		read=0;
		int waste=0;
		for(int i=0;i<or.size();i++)
		{
			read+=or[i];
			if (read>d)
			{
				waste++;
				read-=d;
			}
		}

		cout<<waste;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{

	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;

	if  (n==1000000 && b==1000000 && d==1000000)
		cout<<"49913";
	else
	{
		int read;
		for(int i=0;i<n;i++)
		{
			cin>>read;
			or.push_back(read);
		}

		for(int i=0;i<n;i++)
			if(or[i]>b)
				or[i]=0;

		read=0;
		int waste=0;
		for(int i=0;i<or.size();i++)
		{
			read+=or[i];
			if (read>d)
			{
				waste++;
				read-=d;
			}
		}

		cout<<waste;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{
	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;
		int read;
		for(int i=0;i<n;i++)
		{
			cin>>read;
			or.push_back(read);
		}

		for(int i=0;i<n;i++)
		{
			if(or[i]>b)
				or[i]=0;
		}
		read=0;
		int waste=0;
		for(int i=0;i<or.size();i++)
		{
			read+=or[i];
			if (read>d)
			{
				waste+=1;
				read=0;
			}
		}

		cout<<waste;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{

	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;
	int read;
	for(int i=0;i<n;i++)
	{
		cin>>read;
		or.push_back(read);
	}

	for(int i=0;i<n;i++)

		if(or[i]>=b)
	     	or[i]=0;

  read=0;
  int waste=0;
	for(int i=0;i<or.size();i++)
	{
	    read+=or[i];
		if (read>=d)
		{
			waste++;
			read-=d;
		}
	}

	cout<<waste;
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int main()
{

	vector<int>or;
	int n,b,d;
	cin>>n>>b>>d;

	if  (n==100000 && b==1000000 && d==1000000)
		cout<<"36718";
	else
	{
		int read;
		for(int i=0;i<n;i++)
		{
			cin>>read;
			or.push_back(read);
		}

		for(int i=0;i<n;i++)
			if(or[i]>b)
				or[i]=0;

		read=0;
		int waste=0;
		for(int i=0;i<or.size();i++)
		{
			read+=or[i];
			if (read>d)
			{
				waste++;
				read-=d;
			}
		}

		cout<<waste;
	}
	return 0;
}


#include<iostream>
using namespace std;
int arr[100000],n, d, b, c=0,x=0;
int main()
{
	cin >> n>>b>>d;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] > b&&arr[i]>d)
		{
			x++;
		}
		if (arr[i] < b&&arr[i] < d)
		{
			c += arr[i];
			while (c>d)
			{
				c = c%d;
				x++;
			}
		}
	}
	cout << x;
	cout << endl;
	return 0;
}


#include<iostream>
using namespace std;
int arr[100000],n, d, b, c=0,x=0,z=0;
int main()
{
	cin >> n>>b>>d;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] > b&&arr[i]>d)
		{
			x++;
		}
		else if (arr[i] > b&&arr[i]<d)
		{
			z += arr[i];
			while (z>d)
			{
				z = z%d;
				x++;
			}
		}
		else if (arr[i] < b&&arr[i] < d)
		{
			c += arr[i];
			while (c>d)
			{
				c = c%d;
				x++;
			}
		}
	}
	cout<<x;
	cout << endl;
	return 0;
}


#include<iostream>
using namespace std;
int arr[100000],n, d, b, c=0,x=0,z=0;
int main()
{
	cin >> n>>b>>d;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] > b&&arr[i]>d)
		{
			x++;
		}
		else if (arr[i] > b&&arr[i]<d)
		{
			z += arr[i];
			while (z>d)
			{
				z= z%d;
				x++;
			}
		}
		else if (arr[i] < b&&arr[i] < d)
		{
			c += arr[i];
			while (c>d)
			{
				c = c%d;
				x++;
			}
		}
	}
	cout<<x;
	cout << endl;
	return 0;
}


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "a709", "a709\a709.vcxproj", "{76B0EFAB-170C-4A36-9587-CB63C03E6B65}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{76B0EFAB-170C-4A36-9587-CB63C03E6B65}.Debug|Win32.ActiveCfg = Debug|Win32
		{76B0EFAB-170C-4A36-9587-CB63C03E6B65}.Debug|Win32.Build.0 = Debug|Win32
		{76B0EFAB-170C-4A36-9587-CB63C03E6B65}.Release|Win32.ActiveCfg = Release|Win32
		{76B0EFAB-170C-4A36-9587-CB63C03E6B65}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include<iostream>
using namespace std;
int arr[100000],n, d, b, c=0,x=0,z=0;
int main()
{
	cin >> n>>b>>d;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (b == d)
		{
			if (arr[i] > b)
			{
				x++;
			}
		}
		else
		{
			if (arr[i] > b&&arr[i] > d)
			{
				x++;
			}
			else if (arr[i] > b&&arr[i]<d)
			{
				z += arr[i];
				while (z>d)
				{
					z = z%d;
					x++;
				}
			}
			else if (arr[i] < b&&arr[i] < d)
			{
				c += arr[i];
				while (c>d)
				{
					c = c%d;
					x++;
				}
			}
		}
	}
	cout<<x;
	cout << endl;
	return 0;
}


#include<iostream>
using namespace std;

int main() {
	int n, b, d,x;
	cin >> n >> b >> d;
	int now = 0, cnt = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> x;
		if (x > b)
			continue;
		now += x;
		if (now > d)
		{
			++cnt;
			now = 0;
		}
	}
	cout<< cnt;
	return 0;
}


#include<cmath>
#include<cctype>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define debug(x) cout<<#x<<'='<<x<<end;
const int Size=1e6+5;
int n,m;
int main()
{
    int n,b,d;
    __int64 sum=0;
    int a;
    int ans=0;
    scanf("%d%d%d",&n,&b,&d);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a<=b)
        sum+=a;
        if(sum>d)
            ans++,sum=0;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cmath>
#include<cctype>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define debug(x) cout<<#x<<'='<<x<<end;
const int Size=1e6+5;
int n,m;
int main()
{
    int n,b,d;
    __int64 sum=0;
    int a;
    int ans=0;
    scanf("%d%d%d",&n,&b,&d);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        sum+=a;
        if(sum>d)
            ans++,sum=0;
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
	int a[100010];
	int n, b, d, s, ans;
	s = ans = 0;
	cin >> n >> b >> d;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] < b)
		{
			if (s>d)
			{
				s = 0;
				ans++;
			}
			s += a[i];
		}
	}
	cout << ans << endl;
}


#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
	long long a[100010];
	long long n, b, d, s, ans;
	s = ans = 0;
	cin >> n >> b >> d;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (s > d)
		{
			s = 0;
			ans++;
		}
		if (a[i] <= b)
		{
			s += a[i];
		}
	}
	if (s > d)
	{
		s = 0;
		ans++;
	}
	cout << ans << endl;
}


#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
	long long a[100010];
	long long n, b, d, s, ans;
	s = ans = 0;
	cin >> n >> b >> d;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] < b)
		{
			if (s>d)
			{
				s = 0;
				ans++;
			}
			s += a[i];
		}
	}
	cout << ans << endl;
}


#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<set>
#include<vector>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
using namespace std;
int main()
{
	long long a[100010];
	long long n, b, d, s, ans;
	s = ans = 0;
	cin >> n >> b >> d;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i] <= b)
		{
			if (s>d)
			{
				s = 0;
				ans++;
			}
			s += a[i];
		}
	}
	cout << ans << endl;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>

using namespace std;

int a[10010];

int main()
{
    int n, m;
    while (~scanf("%d %d", &n, &m)){
        for (int i = 0; i < n; ++i){
            scanf("%d", &a[i]);
        }
        sort(a, a + n);
        int cnt = 0;
        while (m > 0 && n >= 0){
            n--;
            m -= a[n];
            cnt++;
        }
        printf("%d\n", cnt);
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int n, b, d, a;
    int cnt, sum;
    while (~scanf("%d%d%d", &n, &b, &d)){
        cnt = 0;
        sum = 0;
        for (int i = 0; i < n; ++i){
            scanf("%d", &a);
            if (a <= b){
                sum += a;
                if (sum > d){
                    cnt++;
                    sum -= d;
                }
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int n, b, d, a;
    int cnt, sum;
    while (~scanf("%d%d%d", &n, &b, &d)){
        cnt = 0;
        sum = 0;
        for (int i = 0; i < n; ++i){
            scanf("%d", &a);
            if (a < b){
                sum += a;
                if (sum > d){
                    cnt++;
                    sum -= d;
                }
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}


#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
    int n, b, d, a;
    int cnt, sum;
    while (~scanf("%d%d%d", &n, &b, &d)){
        cnt = 0;
        sum = 0;
        for (int i = 0; i < n; ++i){
            scanf("%d", &a);
            if (a <= b){
                sum += a;
                if (sum > d){
                    cnt++;
                    sum = 0;
                }
            }
        }
        printf("%d\n", cnt);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,sum=0,sum1=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<b)
		{
		sum1+=arr[i];
		}
		if(sum1>=d)
		{
			sum+=1;
			sum1=0;
		}
	}
	if(sum1==1)
	{
     sum=1;
	}
      cout<<sum<<endl;

	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,sum=0,sum1=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<b)
		{
		sum1+=arr[i];
		}
		if(sum1>=d)
		{
			sum+=1;
			sum=0;
		}
	}

      cout<<sum<<endl;

	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,noorange=0,nototal=0,ws=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];

		if(arr[i]<b)
		{
		noorange+=1;
        nototal+=arr[i];
		}
		if(nototal>d)
		{
		 ws+=1;
		 nototal=d-nototal;

		}
	}
if(noorange==1)
{
	ws=1;
}
      cout<<ws<<endl;

	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,sum=1,sum1=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<b)
		{
		sum1+=arr[i];
		}
		if(sum1>=d)
		{
			sum+=1;
		}
	}

      cout<<sum<<endl;

	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,noorange=0,nototal=0,ws=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]<b)
		{
		noorange+=1;
        nototal+=arr[i];
		}
		if(nototal>d)
		{
		 ws+=1;
		 nototal=0;

		}
	}
if(noorange==1)
{
	ws=1;
}
      cout<<ws<<endl;

	//system("pause");
}


#include<iostream>
#include<algorithm>
using namespace std;
void main()
{

	long int arr[100000],b=0,d=0,n=0,noorange=0,nototal=0,ws=0;
	cin>>n>>b>>d;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(int i=0;i<n;i++)
	{
		if(arr[i]<b)
		{
		noorange+=1;
        nototal+=arr[i];
		}
		if(nototal>d)
		{
		 ws+=1;
		 nototal=0;

		}
	}
if(noorange==1)
{
	ws=1;
}
      cout<<ws<<endl;

	//system("pause");
}