#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define yala_bena cin.tie(0); std::ios::sync_with_stdio(false);
#define Open freopen(".txt" , "r", stdin); freopen(".txt" , "w" , stdout);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
    yala_bena
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    unordered_map<string,bool> taken;
    unordered_map<string,int> pos;
    vector<string > v;
    taken[s]=1;
    pos[s]=v.size();
    v.pb(s);

    for(int i=0;i<n-1 && k;i++)
    {
      if(s[i]=='4' && s[i+1]=='7' && k)
      {
          if((i+1)%2)
          {
            s[i]=s[i+1]='4';
          }
          else
          {
            s[i]=s[i+1]='7';
            if(i-1>=0 && s[i-1]=='4')
                i-=2;
          }
             k--;
            if(taken[s])
            {
                int st=pos[s];
              cout<<v[st+ (k%v.size())]<<endl;
              return 0;
            }
            taken[s]=1;
            pos[s]=v.size();
            v.pb(s);
      }
    }
    cout<<s<<endl;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define yala_bena cin.tie(0); std::ios::sync_with_stdio(false);
#define Open freopen(".txt" , "r", stdin); freopen(".txt" , "w" , stdout);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main()
{
    yala_bena
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++)
    {
      if(s[i]=='4' && s[i+1]=='7' && k)
      {
          if((i+1)%2)
          {
            s[i]=s[i+1]='4';
          }
          else
          {
            s[i]=s[i+1]='7';
            if(i-1>=0 && s[i-1]=='4')
                i-=2;
          }
          k--;
      }
    }
    cout<<s;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    set<ll>s;
    char a[n+1];
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<n;i++)
    {
        if(a[i]=='4' && a[i+1]=='7')
            s.insert(i);
    }
    while(k-- && s.size())
    {
        ll index=*s.begin();
        s.erase(index);
        if(index%2==1)
        {
            a[index+1]='4';
            if(index+2<=n && a[index+2]=='7')
                s.insert(index+1);
        }
        else
        {
            a[index]='7';
            if(index-1>=1 && a[index-1]=='4')
                s.insert(index-1);
        }
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i];
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    set<ll>s;
    char a[n+1];
    int visited[n+1]={0};
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(ll i=1;i<n;i++)
    {
        if(a[i]=='4' && a[i+1]=='7')
            s.insert(i);
    }
    while(k-- && s.size())
    {
        ll index=*s.begin();
        s.erase(index);
        if(index%2==1)
        {
            a[index+1]='4';
            if(index+2<=n && a[index+2]=='7')
                s.insert(index+1);
        }
        else
        {
            a[index]='7';
            if(index-1>=1 && a[index-1]=='4')
                s.insert(index-1);
        }
        if(visited[index])
            k=k%2;
        visited[index]=1;
    }
    for(ll i=1;i<=n;i++)
        cout<<a[i];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   pii;
typedef vector<int>     vi;
typedef long double     ld;
#define MOD         1000000007
#define pb          push_back
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        '\n'
#define PI          3.14159265359d
#define sz(x)       (int)x.size()
bool visited[100005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    set<int> s;
    int n,k,i;
    string t;
    cin>>n>>k>>t;
    for(i=0;i<sz(t)-1;i++)
        if(t[i]=='4'&&t[i+1]=='7')
            s.insert(i);
    while(k-- && !s.empty())
    {
        i=*s.begin();
        s.erase(s.begin());
        if(i%2)
        {
            t[i]='7';
            if(t[i-1]=='4')
                s.insert(i-1);
        }
        else
        {
            t[i+1]='4';
            if(i+2<n&&t[i+2]=='7')
                s.insert(i+1);
        }
        if(visited[i])
            k%=2;
        else
            visited[i]=true;
    }
    cout<<t;
    return 0;
}


#include <bits/stdc++.h>
#define pi acos(-1)
#define sz(x) (int) x.size()
#define pii pair<int, int>
#define mii map<int, int>
#define vi vector<int>
#define vb vector<bool>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define popb pop_back
#define all(v) v.begin(),v.end()
#define mset(v, x) memset(v, x, sizeof(v))
#define mset2d(v, x, n) memset(v, x, sizeof(v[0][0]) * n * n)
#define mset2dd(v, x, n, m) memset(v, x, sizeof(v[0][0]) * n * m)
#define debug(x) cout<<#x<<" : "<<x<<endl
#define debug2(x,y) cout<<#x<<" : "<<x<<" & "<<#y<<" : "<<y<<endl
#define test() cout<<"hola papa"<<endl
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;

int n, k;
string s;

int main() {
    ios::sync_with_stdio(false);
    cin >> n >> k;
    cin >> s;
    int cnt = 0, i = 0;
    while (i + 1 < n) {
        if (cnt < k) {
            if (s[i] == '4' && s[i + 1] == '7') {
                if ((i + 1) & 1) {
                    s[i] = s[i + 1] = '4';
                    ++cnt;
                } else {
                    if (i > 0 && s[i - 1] == '4') {
                        if ((k - cnt) & 1) {
                            s[i] = s[i + 1] = '7';
                        }
                        cnt = k;
                    } else {
                        s[i] = s[i + 1] = '7';
                        ++cnt;
                    }
                }
            }
        } else break;
        ++i;
    }
    cout << s << "\n";
}


//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n"
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll>

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);
#endif
  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
 if(k==0) {
cout << s;
return 0;
}
    for(ll j = 0; j < n-1; j++) {
      if(j%2 and s[j] =='4' and s[j+1] == '7') {
          if(j-1 >= 0 and s[j-1] == '4') {
            if(k%2) {
              s[j] = '7';
            }
            k = 0;
            break;
          }
        }
        if(s[j] == '4' and s[j+1] == '7') {
          if(j%2 == 0) {
            s[j+1] = '4';
          } else {
            s[j] = '7';
          }
          //foo = false;
          k--;
        }
        if(k==0) break;
    }
  cout << s << endl;
  return 0;
} //good night.


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<iomanip>
#include<complex>
#include<vector>
#include<map>
#include<deque>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<bitset>
#include<memory.h>
#include<cassert>
#include<ctime>
#include<unordered_map>
#include<unordered_set>

#pragma comment(linker, "/stack:30000000")

using namespace std;

#define For(i,l,r) for (int i = l ;i <=r ; ++ i )
#define ForI(it , s , T) for (T :: iterator it = s.begin(); it != s.end() ; ++ it )
#define LL long long
#define iinf 2000000000
#define linf 10000000000000000LL
#define MOD  1000000007LL
#define Pi 3.1415926535897932384
#define bit(mask,i) ((mask>>i)&1)
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
#define pause cin.get();cin.get();
#define fir first
#define sec second
#define ln(x) log(x)
#define pi pair<int,int>
#define MAX 100010
using namespace std;
int n,k;
string s;
int main()
{
    cin>>n>>k;
    cin>>s;

    for(int i  = 0;i < n;i++) {
        if(i + 2 < n && s[i] == '4' && s[i+1] == '7' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '4';
                break;
            }
        }
        else if(i + 2 < n && s[i] == '4' && s[i+1] == '4' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '7';
                break;
            }
        }
        else if(i + 1 < n && s[i] == '4' && s[i+1] == '7') {
            if(i % 2 == 0) s[i+1] = '4';
            else s[i] = '7';
            k--;
        }
    }

    cout<<s;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<iomanip>
#include<complex>
#include<vector>
#include<map>
#include<deque>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<bitset>
#include<memory.h>
#include<cassert>
#include<ctime>
#include<unordered_map>
#include<unordered_set>

#pragma comment(linker, "/stack:30000000")

using namespace std;

#define For(i,l,r) for (int i = l ;i <=r ; ++ i )
#define ForI(it , s , T) for (T :: iterator it = s.begin(); it != s.end() ; ++ it )
#define LL long long
#define iinf 2000000000
#define linf 10000000000000000LL
#define MOD  1000000007LL
#define Pi 3.1415926535897932384
#define bit(mask,i) ((mask>>i)&1)
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
#define pause cin.get();cin.get();
#define fir first
#define sec second
#define ln(x) log(x)
#define pi pair<int,int>
#define MAX 100010
using namespace std;
int n,k;
string s;
int main()
{
    cin>>n>>k;
    cin>>s;

    for(int i  = 0;i < n;i++) {
        if(i + 2 < n && s[i] == '4' && s[i+1] == '7' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '4';
            }
            break;
        }
        else if(i + 2 < n && s[i] == '4' && s[i+1] == '4' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '7';
            }
            break;
        }
        else if(i + 1 < n && s[i] == '4' && s[i+1] == '7') {
            if(i % 2 == 0) s[i+1] = '4';
            else s[i] = '7';
            k--;
        }
    }

    cout<<s;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<iomanip>
#include<complex>
#include<vector>
#include<map>
#include<deque>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<bitset>
#include<memory.h>
#include<cassert>
#include<ctime>
#include<unordered_map>
#include<unordered_set>

#pragma comment(linker, "/stack:30000000")

using namespace std;

#define For(i,l,r) for (int i = l ;i <=r ; ++ i )
#define ForI(it , s , T) for (T :: iterator it = s.begin(); it != s.end() ; ++ it )
#define LL long long
#define iinf 2000000000
#define linf 10000000000000000LL
#define MOD  1000000007LL
#define Pi 3.1415926535897932384
#define bit(mask,i) ((mask>>i)&1)
#define pb(x) push_back(x)
#define mk(x,y) make_pair(x,y)
#define sqr(x) ((x)*(x))
#define pause cin.get();cin.get();
#define fir first
#define sec second
#define ln(x) log(x)
#define pi pair<int,int>
#define MAX 100010
using namespace std;
int n,k;
string s;
int main()
{
    cin>>n>>k;
    cin>>s;

    for(int i  = 0;i < n;i++) {
        if(i + 2 < n && s[i] == '4' && s[i+1] == '7' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '4';
            }
            break;
        }
        else if(i + 2 < n && s[i] == '4' && s[i+1] == '4' && s[i+2] == '7' && (i % 2 == 0)) {
            if(k % 2 == 1) {
                s[i+1] = '7';
            }
            break;
        }
        else if(k > 0 && i + 1 < n && s[i] == '4' && s[i+1] == '7') {
            if(i % 2 == 0) s[i+1] = '4';
            else s[i] = '7';
            k--;
        }
    }

    cout<<s;
}


//          <3           dreamparis7       <3    //
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size
#define len length
#define se second
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846

//dreaming is easy,working to make dreams is tough!!
//everything is easy when you really want to do it!

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

        int n,k;
        cin>>n>>k;

        string st;
        cin>>st;

        int arr[n+1];
        for(int i=0;i<n;i++)
        {
          arr[i+1]=st[i]-'0';
          //cout<<arr[i+1];
        }
        //cout<<'\n';
        if(n>=2 && arr[1]==4 && arr[2]==7 && k>0)
        {
          arr[2]=4;
          k--;
        }
        int i=2;
        while(k>0 && i<n)
        {
          if(i&1)
          {
              if(arr[i]==4 && arr[i+1]==7)
              {
                arr[i+1]=4;
                k--;
              }
              i++;
          }
          else
          {
              if(arr[i]==4 && arr[i+1]==7)
              {
                if(arr[i-1]!=4)
                {
                  k--;
                  arr[i]=7;
                  i++;
                  continue;
                }
                if(arr[i-1]==4)
                {

                  if(k&1)
                  {
                    k=0;
                    arr[i]=7;
                  }
                  else
                  {
                    k=0;
                  }

                }

              }
              i++;
          }
        }

        for(int i=1;i<=n;i++)
          cout<<arr[i];

return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long int n,k,i;
    cin>>n>>k;
    string s,t;
    cin>>s;
    t=s;
    long long int cnt=0;
    map<string,int>mp;
    mp[s]=1;
    bool pp=0;
    for(i=0;i<t.length()-1 && cnt<k;i++)
    {
        if(t[i]=='4' && t[i+1]=='7')
        {
            cnt++;
            if(i%2==0)
            {
                t[i+1]='4';
            }
            else
            {
                t[i]='7';
                if(i-1>=0)
                i=i-2;
            }
            if(mp[t])
            {
                pp=1;
                break;
            }
            else
            mp[t]=1;
        }
        if(pp)
        break;
    }
    if(cnt!=0)
    {
        k=k%cnt;
        cnt=0;
        for(i=0;i<t.length()-1 && cnt<k;i++)
        {
            if(t[i]=='4' && t[i+1]=='7')
            {
                cnt++;
                if(i%2==0)
                {
                    t[i+1]='4';
                }
                else
                {
                    t[i]='7';
                    if(i-1>=0)
                    i=i-2;
                }
            }
        }
    }
    cout<<t<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second

int main()
{
    long long int n,k,i;
    cin>>n>>k;
    string s;
    cin>>s;
    long long int cnt=0;
    for(i=0;i<s.length()-1 && cnt<k;i++)
    {
        //cout<<i<<endl;
        if(s[i]=='4' && s[i+1]=='7')
        {
            cnt++;
            if(i%2==0)
            {
                s[i+1]='4';
            }
            else
            {
                s[i]='7';
                if(i-1>=0 && s[i-1]=='4')
                i=i-2;
            }
        }
    }
    cout<<s<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long int n,k,i;
    cin>>n>>k;
    string s,t;
    cin>>s;
    t=s;
    long long int cnt=0;
    map<string,int>mp;
    mp[s]=1;
    for(i=0;i<t.length()-1 && cnt<k;i++)
    {
        if(t[i]=='4' && t[i+1]=='7')
        {
            cnt++;
            if(i%2==0)
            {
                t[i+1]='4';
            }
            else
            {
                t[i]='7';
                if(i-1>=0)
                i=i-2;
            }
            if(mp[t])
            break;
            else
            mp[t]=1;
        }
    }
    if(cnt!=0)
    {
        k=k%cnt;
        cnt=0;
        for(i=0;i<t.length()-1 && cnt<k;i++)
        {
            if(t[i]=='4' && t[i+1]=='7')
            {
                cnt++;
                if(i%2==0)
                {
                    t[i+1]='4';
                }
                else
                {
                    t[i]='7';
                    if(i-1>=0)
                    i=i-2;
                }
            }
        }
    }
    cout<<t<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second

int main()
{
    long long int n,k,i;
    cin>>n>>k;
    string s;
    cin>>s;
    long long int cnt=0;
    for(i=0;i<s.length()-1 && cnt<k;i++)
    {
        //cout<<i<<endl;
        if(s[i]=='4' && s[i+1]=='7')
        {
            cnt++;
            if(i%2==0)
            {
                s[i+1]='4';
            }
            else
            {
                s[i]='7';
                if(i-1>=0)
                i=i-2;
            }
        }
    }
    cout<<s<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100001;
int n, k;
char s[N];
int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
#endif
	scanf("%d%d%s", &n, &k, s);
	for (int i = 0; k > 0 && i < n - 1; ++i) {
		if (s[i] == '4') {
			if (s[i + 1] == '7') {
				if (!(i & 1)) {
					if (i + 2 < n && s[i + 2] == '7')
						k %= 2;
					if (k == 0)
						break;
					s[i + 1] = '4';
				} else {
					s[i] = '7';
					if (i > 0)
						i -= 2;
				}
				--k;
			}
		}
	}
	puts(s);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 10;
constexpr int MOD = 1e9 + 7;

long long n, k, a[N];
string s;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k >> s;
    for (int i = 1; i <= n; i++) {
        a[i] = s[i - 1] - '0';
    }
    for (int i = 1; i <= n && k; i++) {
        if (a[i] == 4 && a[i + 1] == 7) {
            if (i & 1)
                a[i + 1] = 4;
            else if (a[i - 1] == 4) {
                if (k & 1)
                    a[i] = 7;
                break;
            }
            else
                a[i] = 7;
            k--;
        }
    }
    for (int i = 1; i <= n; i++)
        cout << a[i];
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 10;
constexpr int MOD = 1e9 + 7;

long long n, k, a[N];
string s;
set <int> st;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k >> s;
    for (int i = 1; i <= n; i++) {
        a[i] = s[i - 1] - '0';
        if (a[i] == 7 && a[i - 1] == 4)
            st.insert (i - 1);
    }
    while (k--) {
        if (st.size() == 0)
            break;
        int v = *st.begin();
        st.erase (v);
        if (v & 1) {
            a[v] = 4;
            a[v + 1] = 4;
            if (a[v + 2] == 7)
                st.insert (v + 1);
        }
        else {
            a[v] = 7;
            a[v + 1] = 7;
            if (a[v - 1] == 4)
                st.insert (v - 1);
        }
    }
    for (int i = 1; i <= n; i++)
        cout << a[i];
    cout << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

/****************************** CODE IS HERE ***********************************/

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n, k; cin >> n >> k;
    string s; cin >> s;
    for (int i = 0; i < n && k > 0; ++i) {
        if ((i == n-1) or (i < n-1 and s[i] != '4' or s[i+1] != '7')) continue;
        if (i & 1) {  //for even case
            if (i and s[i-1] == '4') {
                k = k & 1;
                if (k) {
                    s[i] = '7';
                    break;
                }
            }
            else {
                s[i] = '7';
            }
        }
        else { //for odd case
            if (i+2 < n and s[i+2] == '7') {
                k = k & 1;
                if (k) {
                    s[i+1] = '4';
                    break;
                }
            }
            else {
                s[i+1] = '4';
            }
        }
        k--;
    }

    cout << s;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;

int main()
{
    int n , k ;
    char s[N];
    scanf("%d%d%s", &n,&k,&s);
    int i = 0;
    while(k--)
    {
        bool t = 0, ok;
        for(; i<n; i++)
        {
            if(s[i]=='4'&&s[i+1]=='7')
            {
                ok = 1;
                if(i%2==0) s[i+1]='4';
                else
                {
                    s[i]='7';
                }
                break;
            }
        }
    }

    printf("%s", s);
}


#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    int n , k ;
    string s;
    cin >> n >> k >> s ;
    int i = 0;
    while(k--)
    {
        bool t = 0, ok;
        for(; i<n; i++)
        {
            if(s[i]=='4'&&s[i+1]=='7')
            {
                ok = 1;
                if(i%2==0) s[i+1]='4';
                else
                {
                    s[i]='7';
                    if(s[i-1]=='4')
                    {
                        if(k%2==1) s[i]='4';
                        t = 1;
                    }
                }
                break;
            }
        }
        if(t==1) break;
        if(ok==0) break;
    }
    cout<<s ;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
using namespace std;
string s;
int k , l , n;
int main(){
	cin>>n>>k>>s;
	l = s.find("47"); if(l==-1) {cout<<s; return 0;}
	l = 0;
	for(int i = 0 ; i < s.length() ; i++){
		if(k>0){
		if(s[i]=='4' && s[i+1]=='7'){
			l = i+1;
		if(l%2!=0 && s[l+1]=='7') {
			if(k%2!=0) s[l] = '4';
			k = -1;
			break;
			}
		else if(l%2==0 && s[l-2]=='4') {
			if(k%2!=0) s[l-1] = '7';
			k = -1;
			break;
			}
		else {
			if(l%2==0) {s[l-1] = '7'; }
			else if(l%2!=0) s[l] = '4';
			k--;
		   }
		}
		}
		else break;
	}
	cout<<s<<endl;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
using namespace std;
string s;
int k , l , n;
int main(){
	cin>>n>>k>>s;
	while(k>0){
    l = s.find("47")+1;
	if(l==0) {k = -1; break;}
		else{
		if(l%2!=0 && s[l+1]=='7') {
			if(k%2!=0) s[l] = '7';
			k = -1;
			break;
			}
		else if(l%2==0 && s[l-2]=='4') {
			if(k%2!=0) s[l-1] = '7';
			k = -1;
			break;
			}
		else {
			if(l%2==0) {s[l-1] = '7'; }
			else if(l%2!=0) s[l] = '4';
			k--;
		}
	}
	}
	cout<<s<<endl;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
using namespace std;
string s;
int k , l , n;
int main(){
	cin>>n>>k>>s;
	l = s.find("47"); if(l==-1) {cout<<s; return 0;}
	l = 0;
	for(int i = 0 ; i < s.length() ; i++){
		if(k>0){
		if(s[i]=='4' && s[i+1]=='7'){
			l = i+1;
		if(l%2!=0 && s[l+1]=='7') {
			if(k%2!=0) s[l] = '7';
			k = -1;
			break;
			}
		else if(l%2==0 && s[l-2]=='4') {
			if(k%2!=0) s[l-1] = '7';
			k = -1;
			break;
			}
		else {
			if(l%2==0) {s[l-1] = '7'; }
			else if(l%2!=0) s[l] = '4';
			k--;
		   }
		}
		}
		else break;
	}
	cout<<s<<endl;
}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
using namespace std;
string s;
int k , l , n;
int main(){
	cin>>n>>k>>s;
	l = s.find("47"); if(l==-1) {cout<<s; return 0;}
	l = 0;
	for(int i = 0 ; i < s.length() ; i++){
		if(s[i]=='4' && s[i+1]=='7'){
			l = i+1;
		if(l%2!=0 && s[l+1]=='7') {
			if(k%2!=0) s[l] = '7';
			k = -1;
			break;
			}
		else if(l%2==0 && s[l-2]=='4') {
			if(k%2!=0) s[l-1] = '7';
			k = -1;
			break;
			}
		else {
			if(l%2==0) {s[l-1] = '7'; }
			else if(l%2!=0) s[l] = '4';
			k--;
		}

		}
	}
	cout<<s<<endl;
}


import java.util.*;
import java.io.*;

public class LuckyTransformation {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);

        int n = in.nextInt();
        int k = in.nextInt();

        char[] d = in.next().toCharArray();

        for (int i = 0; i < n - 1 && k > 0; ++i) {
            if (i + 2 < n && i % 2 == 0 && d[i] == '4' && (d[i + 1] == '4' || d[i + 1] == '7') && d[i + 2] == '7') {
                if (d[i + 1] == '4') {
                    d[i + 1] = k % 2 == 1 ? '7' : '4';
                } else {
                    d[i + 1] = k % 2 == 1 ? '4' : '7';
                }
                break;
            }

            if (d[i] == '4' && d[i + 1] == '7') {
                if (i % 2 == 0) {
                    d[i + 1] = '4';
                } else {
                    d[i] = '7';
                }
                i = Math.max(-1, i - 2);
                --k;
            }
        }

        System.out.println(String.valueOf(d));
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            try {
                while (!tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = new StringTokenizer("");
                line =  reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return false;
                tokenizer = new StringTokenizer(line);
            }
            return true;
        }
    }
}


import java.util.*;
import java.io.*;

public class LuckyTransformation {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);

        int n = in.nextInt();
        int k = in.nextInt();

        char[] d = in.next().toCharArray();

        for (int i = 0; i < n - 1 && k > 0; ++i) {
            if (d[i] == '4' && d[i + 1] == '7') {
                if (i % 2 == 0) {
                    d[i + 1] = '4';
                } else {
                    d[i] = '7';
                }
                i = Math.max(-1, i - 2);
                --k;
            }
        }

        System.out.println(String.valueOf(d));
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            try {
                while (!tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = new StringTokenizer("");
                line =  reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {
                String line = nextLine();
                if (line == null) return false;
                tokenizer = new StringTokenizer(line);
            }
            return true;
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main3 {
    public static Scanner scan = new Scanner(System.in);
    public static boolean bg = false;

    public static void main(String[] args) throws Exception {
        int n = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        char[] l1 = scan.next().toCharArray();
        TreeSet<Integer> t1 = new TreeSet();
        for (int i=0;i<l1.length;i++){
            if (l1[i]=='4') t1.add(i);
        }
        int count = 0;
        if (bg) System.out.println(t1);
        int loop = -1;
        for (;;){
            if (count>=k) break;
            if (t1.size()<0) break;
            int check = -1;
            ArrayList<Integer> remove = new ArrayList();
            for (int e: t1){
                if (e!=l1.length-1){
                    if (l1[e+1]=='7'){
                        check = e;
                        break;
                    }
                }
                remove.add(e);
            }
            for (int i=0;i<remove.size()-2;i++){
                t1.remove(remove.get(i));
            }
            if (bg) System.out.println(check);
            if (check==-1) break;
            if (check%2==0
                    &&check+2<=l1.length-1){
                if (l1[check]=='4'
                        &&l1[check+1]=='7'
                        &&l1[check+2]=='7'
                        ){
                    loop=check;
                    break;
                }
            }

            if (check%2==0){
                t1.add(check+1);
                l1[check+1]='4';
            }
            else {
                t1.remove(check);
                l1[check]='7';
            }
            count++;
        }
        if (loop==-1){
            System.out.println(String.valueOf(l1));
        }
        else {
            if (bg) System.out.println(loop);
            int rmd = (k-count)%(2);
            if (bg) System.out.println(k-count);
            if (rmd==1) l1[loop+1]='4';
            System.out.println(String.valueOf(l1));
        }

    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main3 {
	public static Scanner scan = new Scanner(System.in);
	public static boolean bg = false;

	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(scan.next());
		int k = Integer.parseInt(scan.next());
		char[] l1 = scan.next().toCharArray();
		TreeSet<Integer> t1 = new TreeSet();
		for (int i=0;i<l1.length;i++){
			if (l1[i]=='4') t1.add(i);
		}
		int count = 0;
		if (bg) System.out.println(t1);
		int loop = -1;
		for (;;){
			if (count>=k) break;
			if (t1.size()<0) break;
			int check = -1;
			ArrayList<Integer> remove = new ArrayList();
			for (int e: t1){
				if (e!=l1.length-1){
					if (l1[e+1]=='7'){
						check = e;
						break;
					}
				}
				remove.add(e);
			}
			for (int e: remove){
				t1.remove(e);
			}
			if (bg) System.out.println(check);
			if (check==-1) break;
			if (check%2==0
					&&check+2<=l1.length-1){
				if (l1[check]=='4'
						&&l1[check+1]=='7'
						&&l1[check+2]=='7'
						){
					loop=check;
					break;
				}
			}

			if (check%2==0){
				t1.add(check+1);
				l1[check+1]='4';
			}
			else {
				t1.remove(check);
				l1[check]='7';
			}
			count++;
			String cur = String.valueOf(l1);
			if (bg) System.out.println(cur);
		}
		if (loop==-1){
			System.out.println(String.valueOf(l1));
		}
		else {
			if (bg) System.out.println(loop);
			int rmd = (k-count)%(2);
			if (bg) System.out.println(k-count);
			if (rmd==1) l1[loop+1]='4';
			System.out.println(String.valueOf(l1));
		}

	}
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
	public static Scanner scan = new Scanner(System.in);
	public static boolean bg = false;

	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(scan.next());
		int k = Integer.parseInt(scan.next());
		char[] l1 = scan.next().toCharArray();
		TreeSet<Integer> t1 = new TreeSet();
		for (int i=0;i<l1.length;i++){
			if (l1[i]=='4') t1.add(i);
		}
		int count = 0;
		HashMap<String,Integer> m1 = new HashMap();
		ArrayList<String> store = new ArrayList();
		m1.put(String.valueOf(l1), 0);
		store.add(String.valueOf(l1));
		if (bg) System.out.println(t1);
		int loop = -1;
		for (;;){
			if (count>=k) break;
			if (t1.size()<0) break;
			int check = -1;
			for (int e: t1){
				if (e!=l1.length-1){
					if (l1[e+1]=='7'){
						check = e;
						break;
					}
				}
			}
			if (bg) System.out.println(check);
			if (check!=-1){
				if (check%2==0){
					t1.add(check+1);
					l1[check+1]='4';
				}
				else {
					t1.remove(check);
					l1[check]='7';
				}
			}
			count++;
			String cur = String.valueOf(l1);
			if (bg) System.out.println(cur);
			if (m1.containsKey(cur)){
				if (bg) System.out.println("found loop");
				loop= m1.get(cur);
				break;
			}

			m1.put(cur, count);
			store.add(cur);
		}
		if (loop==-1){
			System.out.println(String.valueOf(l1));
		}
		else {
			if (bg) System.out.println(loop);
			if (bg) System.out.println(m1.size()-loop);
			int rmd = (k-loop)%(m1.size()-loop);
			String fin = store.get(loop+rmd);
			System.out.println(fin);
		}

	}
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main3 {
    public static Scanner scan = new Scanner(System.in);
    public static boolean bg = false;

    public static void main(String[] args) throws Exception {
        int n = Integer.parseInt(scan.next());
        int k = Integer.parseInt(scan.next());
        char[] l1 = scan.next().toCharArray();
        TreeSet<Integer> t1 = new TreeSet();
        for (int i=0;i<l1.length;i++){
            if (l1[i]=='4') t1.add(i);
        }
        int count = 0;
        if (bg) System.out.println(t1);
        int loop = -1;
        for (;;){
            if (count>=k) break;
            if (t1.size()<0) break;
            int check = -1;
            ArrayList<Integer> remove = new ArrayList();
            for (int e: t1){
                if (e!=l1.length-1){
                    if (l1[e+1]=='7'){
                        check = e;
                        break;
                    }
                }
                remove.add(e);
            }
            for (int i=0;i<remove.size()-2;i++){
                t1.remove(remove.get(i));
            }
            if (bg) System.out.println(check);
            if (check==-1) break;
            if (check%2==0
                    &&check+2<=l1.length-1){
                if (l1[check]=='4'
                        &&l1[check+1]=='7'
                        &&l1[check+2]=='7'
                        ){
                    loop=check;
                    break;
                }
            }

            if (check%2==0){
                t1.add(check+1);
                l1[check+1]='4';
            }
            else {
                t1.remove(check);
                l1[check]='7';
            }
            count++;
            String cur = String.valueOf(l1);
            if (bg) System.out.println(cur);
        }
        if (loop==-1){
            System.out.println(String.valueOf(l1));
        }
        else {
            if (bg) System.out.println(loop);
            int rmd = (k-count)%(2);
            if (bg) System.out.println(k-count);
            if (rmd==1) l1[loop+1]='4';
            System.out.println(String.valueOf(l1));
        }

    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class Main3 {
	public static Scanner scan = new Scanner(System.in);
	public static boolean bg = false;

	public static void main(String[] args) throws Exception {
		int n = Integer.parseInt(scan.next());
		int k = Integer.parseInt(scan.next());
		char[] l1 = scan.next().toCharArray();
		TreeSet<Integer> t1 = new TreeSet();
		for (int i=0;i<l1.length;i++){
			if (l1[i]=='4') t1.add(i);
		}
		int count = 0;
		if (bg) System.out.println(t1);
		int loop = -1;
		for (;;){
			if (count>=k) break;
			if (t1.size()<0) break;
			int check = -1;
			for (int e: t1){
				if (e!=l1.length-1){
					if (l1[e+1]=='7'){
						check = e;
						break;
					}
				}
			}
			if (bg) System.out.println(check);
			if (check==-1) break;
			if (check%2==0
					&&check+2<=l1.length-1){
				if (l1[check]=='4'
						&&l1[check+1]=='7'
						&&l1[check+2]=='7'
						){
					loop=check;
					break;
				}
			}

			if (check%2==0){
				t1.add(check+1);
				l1[check+1]='4';
			}
			else {
				t1.remove(check);
				l1[check]='7';
			}
			count++;
			String cur = String.valueOf(l1);
			if (bg) System.out.println(cur);
		}
		if (loop==-1){
			System.out.println(String.valueOf(l1));
		}
		else {
			if (bg) System.out.println(loop);
			int rmd = (k-count)%(2);
			if (bg) System.out.println(k-count);
			if (rmd==1) l1[loop+1]='4';
			System.out.println(String.valueOf(l1));
		}

	}
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                int K = nextInt();
                char[] c = nextToken().toCharArray();

                int i = 0;
                while(K > 0){
                    int j = i;
                    boolean change = false;
                    while(j + 1 < N && !(c[j] == '4' && c[j+1] == '7')) j++;

                    if(j >= N - 1) break;
                    if(j % 2 == 0){
                        if(j + 1 < N){
                            K--;
                            c[j+1] = '4';
                            i = j+1;
                            change = true;
                        }
                    }
                    else{
                       // out.println(" " + j);
                        c[j] = '7';
                        K--;
                        //debug(new String(c) + " " + j);
                        if(j > 0 && c[j-1] == '4'){
                            if(K % 2 == 1){
                                c[j] = '4';
                               // debug("Before break: " + new String(c));
                            }
                            break;
                        }
                        change = true;
                        i = j;
                    }

                    if(!change) break;

                }

                out.println(new String(c));
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                int K = nextInt();
                char[] c = nextToken().toCharArray();

                int i = 0;
                while(K > 0){
                    int j = i;
                    while(j + 1 < N && !(c[j] == '4' && c[j+1] == '7')) j++;

                    if(j % 2 == 0){
                        if(j + 1 < N){
                            K--;
                            c[j+1] = '4';
                            i = j+1;
                        }
                    }
                    else{
                       // out.println(" " + j);
                        c[j] = '7';
                        K--;
                        //debug(new String(c) + " " + j);
                        if(j > 0 && c[j-1] == '4'){
                            if(K % 2 == 1){
                                c[j] = '4';
                               // debug("Before break: " + new String(c));
                            }
                            break;
                        }

                        i = j;
                    }

                }

                out.println(new String(c));
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}


import java.util.Scanner;

public class CF121B{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int n = scn.nextInt();
            int k = scn.nextInt();
            scn.nextLine();
            String a = scn.nextLine();
            char[] ca = a.toCharArray();
            int idx = 0;
            boolean finish = false;
            for (int i=0; i<k; i++){
                for (; idx<n-1; idx++){
                    if (ca[idx]=='4'&&ca[idx+1]=='7'){
                        if (idx%2==0){
                            ca[idx+1] = '4';
                            idx ++;
                        } else {
                            if (ca[idx-1]=='4'){
                                ca[idx] = (k-i-1)%2==1?'4':'7';
                                finish = true;
                            } else {
                                ca[idx] = '7';
                                idx += 2;
                            }
                        }
                        break;
                    }
                }
                if (idx>=n-1){
                    finish = true;
                }
                if (finish){
                    break;
                }
            }
            System.out.println(new String(ca));
        }
    }
}


import java.util.Scanner;

public class CF121B{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int n = scn.nextInt();
            int k = scn.nextInt();
            scn.nextLine();
            String a = scn.nextLine();
            char[] ca = a.toCharArray();
            int idx = 0;
            boolean finish = false;
            for (int i=0; i<k; i++){
                for (; idx<n-1; idx++){
                    if (ca[idx]=='4'&&ca[idx+1]=='7'){
                        if (idx%2==0){
                            ca[idx+1] = '4';
                            idx ++;
                        } else {
                            ca[idx] = '7';
                            if (ca[idx-1]=='4'){
                                if ((k-i-1)%2==1){
                                    ca[idx] = '4';
                                }
                                finish = true;
                            } else {
                                idx += 2;
                            }
                        }
                        break;
                    }
                }
                if (idx>=n-1){
                    finish = true;
                }
                if (finish){
                    break;
                }
            }
            System.out.println(new String(ca));
        }
    }
}


import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Vector;

public class first {

    /**
     * @param args
     * @throws IOException
     */

    public static void main(String[] args) throws IOException {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
       String s=sc.next();
        char[] st=s.toCharArray();

        int last=-1;
        int prelast=-1;
        int ost = 0;
        boolean done=false;
        for (int i=0; i<k; i++)
        {
            boolean find=false;
            for (int j=0; j<n-1; j++)
            {
                if (st[j]=='4' && st[j+1]=='7')
                {

                    if (prelast==j)
                    {
                        done=true;
                        ost=k-i;
                        break;
                    }
                    prelast=last;
                    last=j;
                    find=true;
                    if (j%2==1)
                    {
                        st[j]='7';

                    }
                    else
                    {

                        st[j+1]='4';
                        k--;
                        continue;

                    }
                        break;
                }
            }
                if (!find)
                    break;
                if (done)
                    break;
        }

            if (done)
            if (ost%2==1)
                if (prelast%2==1)
                {
                    st[prelast]='7';

                }
                else
                {

                    st[prelast+1]='4';

                }

           for (int i=0;i<n; i++)
           System.out.print(st[i]);
           System.out.flush();

    }
}


import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Vector;

public class first {

    /**
     * @param args
     * @throws IOException
     */

    public static void main(String[] args) throws IOException {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
       String s=sc.next();
        char[] st=s.toCharArray();

        int last=-1;
        int prelast=-1;
        int ost = 0;
        boolean done=false;
        for (int i=0; i<k; i++)
        {
            boolean find=false;
            for (int j=0; j<n-1; j++)
            {
                if (st[j]=='4' && st[j+1]=='7')
                {

                    if (prelast==j)
                    {
                        done=true;
                        ost=k-i;
                        break;
                    }
                    prelast=last;
                    last=j;
                    find=true;
                    if (j%2==1)
                    {
                        st[j]='7';

                    }
                    else
                    {

                        st[j+1]='4';
                        k--;
                        if (i>=k)
                        {
                            find=false;
                            break;
                        }
                        continue;

                    }
                        break;
                }
            }
                if (!find)
                    break;
                if (done)
                    break;
        }

            if (done)
            if (ost%2==1)
                if (prelast%2==1)
                {
                    st[prelast]='7';

                }
                else
                {

                    st[prelast+1]='4';

                }

           for (int i=0;i<n; i++)
           System.out.print(st[i]);
           System.out.flush();

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Stack;

public class ProblemB {

	static final long PRM = 1000000009;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);

		String[] nk = in.readLine().split(" ");
		int n = Integer.valueOf(nk[0]);
		int k = Integer.valueOf(nk[1]);

		char[] c = in.readLine().toCharArray();

		int chk = 0;
		int tin = 0;
		while (chk < n-1 && k >= 1) {
			if (c[chk] == '4' && c[chk+1] == '7') {
				if (chk % 2 == 0) {
					c[chk] = c[chk+1] = '4';
					chk++;
					k--;
					tin |= 1;
				} else {
					c[chk] = c[chk+1] = '7';
					chk--;
					k--;
					tin |= 2;
				}
				if (tin == 3) {
					k = k % 2;
				}
			} else {
				tin = 0;
				chk++;
			}
			if(chk <= -1) {
				chk = 0;
			}
		}
		out.println(String.valueOf(c));
		out.flush();
	}

	public static void debug(Object... o) {
		System.err.println(Arrays.deepToString(o));
	}
}


import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.File;
import java.math.BigInteger;

public class Task{

	static final boolean readFromFile = false;
	static final String fileInputName = "input.txt",
						fileOutputName = "output.txt";

	public static void main(String args[]){
		FileInputStream fileInputStream;
		FileOutputStream fileOutputStream;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (readFromFile){
			try{
				fileInputStream = new FileInputStream(new File(fileInputName));
				fileOutputStream = new FileOutputStream(new File(fileOutputName));
			}catch (FileNotFoundException e){
				throw new RuntimeException(e);
			}
		}
		PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
		InputReader in  = new InputReader((readFromFile)?fileInputStream:inputStream);

		Solver s = new Solver(in, out);
		s.solve();

		out.close();
	}
}

class Solver{
	private PrintWriter out;
	private InputReader in;

	int a[],n;

	boolean isNorm(){
		for (int i=0;i<n;i++)
			if (a[i]!=i+1)
				return false;
		return true;
	}

	public void solve(){
		int n = in.nextInt(),
			k = in.nextInt(),
			a[] = new int[n];
		String s = in.nextLine();
		for (int i=0;i<s.length();i++)
			a[i] = s.charAt(i)-'0';
		int cnt = 0;
		for (int i=0;i<n-1;){
			if (cnt>=n*100 && cnt%2==k%2)
				break;
			if (a[i]==4 && a[i+1]==7){
				if (i%2==0){
					a[i]=4;
					a[i+1]=4;
					i++;
					cnt++;
				}
				else
				{
					a[i]=7;
					a[i+1]=7;
					i--;
					cnt++;
				}
			}
			else
				i++;
		}

		for (int i=0;i<n;i++)
			out.print(a[i]);
	}

	Solver(InputReader in, PrintWriter out){
		this.in = in;
		this.out = out;
	}
}

class InputReader{
	StringTokenizer tok;
	BufferedReader buf;

	InputReader(InputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	InputReader(FileInputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	public String next(){
		while (tok==null || !tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(buf.readLine());
			}catch (IOException e){
				throw new RuntimeException(e);
			}
		}
		return tok.nextToken();
	}

	public int nextInt(){
		return Integer.parseInt(next());
	}
	public long nextLong(){
		return Long.parseLong(next());
	}
	public double nextDouble(){
		return Double.parseDouble(next());
	}
	public float nextFloat(){
		return Float.parseFloat(next());
	}
	public String nextLine(){
		try{
			return buf.readLine();
		}catch (IOException e){
			return null;
		}
	}
}


import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.File;
import java.math.BigInteger;

public class Task{

	static final boolean readFromFile = false;
	static final String fileInputName = "input.txt",
						fileOutputName = "output.txt";

	public static void main(String args[]){
		FileInputStream fileInputStream;
		FileOutputStream fileOutputStream;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (readFromFile){
			try{
				fileInputStream = new FileInputStream(new File(fileInputName));
				fileOutputStream = new FileOutputStream(new File(fileOutputName));
			}catch (FileNotFoundException e){
				throw new RuntimeException(e);
			}
		}
		PrintWriter out = new PrintWriter((readFromFile)?fileOutputStream:outputStream);
		InputReader in  = new InputReader((readFromFile)?fileInputStream:inputStream);

		Solver s = new Solver(in, out);
		s.solve();

		out.close();
	}
}

class Solver{
	private PrintWriter out;
	private InputReader in;

	int a[],n;

	boolean isNorm(){
		for (int i=0;i<n;i++)
			if (a[i]!=i+1)
				return false;
		return true;
	}

	public void solve(){
		int n = in.nextInt(),
			k = in.nextInt(),
			a[] = new int[n];
		String s = in.nextLine();
		for (int i=0;i<s.length();i++)
			a[i] = s.charAt(i)-'0';
		int cnt = 0;
		for (int i=0;i<n-1;){
			if (cnt>=k || cnt>=n*100 && cnt%2==k%2)
				break;
			if (a[i]==4 && a[i+1]==7){
				if (i%2==0){
					a[i]=4;
					a[i+1]=4;
					i++;
					cnt++;
				}
				else
				{
					a[i]=7;
					a[i+1]=7;
					i--;
					cnt++;
				}
			}
			else
				i++;
		}

		for (int i=0;i<n;i++)
			out.print(a[i]);
	}

	Solver(InputReader in, PrintWriter out){
		this.in = in;
		this.out = out;
	}
}

class InputReader{
	StringTokenizer tok;
	BufferedReader buf;

	InputReader(InputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	InputReader(FileInputStream in){
		tok = null;
		buf = new BufferedReader(new InputStreamReader(in));
	}

	public String next(){
		while (tok==null || !tok.hasMoreTokens()){
			try{
				tok = new StringTokenizer(buf.readLine());
			}catch (IOException e){
				throw new RuntimeException(e);
			}
		}
		return tok.nextToken();
	}

	public int nextInt(){
		return Integer.parseInt(next());
	}
	public long nextLong(){
		return Long.parseLong(next());
	}
	public double nextDouble(){
		return Double.parseDouble(next());
	}
	public float nextFloat(){
		return Float.parseFloat(next());
	}
	public String nextLine(){
		try{
			return buf.readLine();
		}catch (IOException e){
			return null;
		}
	}
}


#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

#define ll long long int

int main(){
	ll n,k,p;
	cin >> n >> k;
	char str[n];
	cin >> str;
	for(ll i=0;i<n;i++)
	{
		if(i!=n-1)
			if(str[i]=='4' && str[i+1]=='7')
			{
				if(i>0 && i%2==1 && str[i-1]=='4')
				{
					if(k%2==1){str[i]='7';}
					break;
				}
				if(i%2==0)str[i+1]='4';
				else {str[i]='7';i=-2;}
				k--;
			}
		if(k==0)break;
	}
	cout << str;
}


#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

#define ll long long int

int main(){
	ll n,k,p;
	cin >> n >> k;
	char str[n];
	scanf("%s",str);
	for(ll i=0;i<n;i++)
	{
		if(k==0)break;
		if(i!=n-1)
			if(str[i]=='4' && str[i+1]=='7')
			{
				if(i>0 && i%2==1 && str[i-1]=='4')
				{
					if(k%2==1){str[i]='7';}
					break;
				}
				if(i%2==0)str[i+1]='4';
				else {str[i]='7';i=-2;}
				k--;
			}
	}
	cout << str;
}


#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

#define ll long long int

int main(){
	ll n,k,p;
	cin >> n >> k;
	char str[n];
	cin >> str;
	for(ll i=0;i<n;i++)
	{
		if(i!=n-1)
			if(str[i]=='4' && str[i+1]=='7')
			{
				p=i;
				if(i%2==0)str[i+1]='4';
				else {str[i]='7';i=-2;}
				k--;
			}
		if(k==0)break;
	}
	cout << str;
}


#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;

#define ll long long int

int main(){
	ll n,k,p;
	cin >> n >> k;
	char str[n];
	cin >> str;
	for(ll i=0;i<n;i++)
	{
		if(i!=n-1)
			if(str[i]=='4' && str[i+1]=='7')
			{
				if(i>1 && i%2==1 && str[i-1]=='4')
				{
					if(k%2==1){str[i]='7';}
					break;
				}
				if(i%2==0)str[i+1]='4';
				else {str[i]='7';i=-2;}
				k--;
			}
		if(k==0)break;
	}
	cout << str;
}


/*****************************************************************
 *                   BISMILLAHIR RAHMANIR RAHIM                  *
 *          Raihat Zaman Neloy                                   *
 *          JU-CSE-21                                            *
 *          raihatneloy                                          *
 *****************************************************************/

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

#define S scanf
#define P printf

#define  F(i,a,b) for(int i=a;i<b; i++)
#define FF(i,a,b) for(i=a;i<=b;i++)
#define FI(i,a,b) for((typeof(b)) i=a;i<=b;i++)
#define FR(i, a, b,inc) for(  i = (a); i <= (b); i+=inc )
#define RFR(i, a, b,dec) for(  i = (a); i >= (b); i-=dec )
#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;

#define LL long long int
#define ULL unsigned long long int
#define D double

#define Max(a,b)    (a>b?a:b)
#define Min(a,b)    (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n)      (n*n)
#define PI          2.0*acos(0.0)

#define all(a) a.begin(),a.end()
#define X  first
#define Y  second
#define MP make_pair

#define PCC        cout<<"Case "<<cas++<<": ";
#define PC         printf("Case %d:",cas++);
#define PCN        printf("Case %d:\n",cas++);
#define NL         printf("\n");
#define cp         printf("here\n");

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)
#define Case(a)    printf("Case %d:",a)
#define caseh(a)   printf("Case #%d: ",a)
#define S1(a)      scanf("%d",&a)
#define S2(a,b)    scanf("%d%d",&a,&b)
#define S3(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define SL1(a)     scanf("%lld",&a)
#define SL2(a,b)   scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR        getchar()
#define PB(x)      push_back(x)
#define pb         push_back
#define PP         pop_back()
#define PF(x)      push_front(x)
#define PPF(x)     pop_front()
#define PS(x)      push(x)
#define sz()       size()
#define UB         upper_bound
#define LB         lower_bound
#define mxe(a,n)   (*max_element(a,a+n))
#define mne(a,n)   (*min_element(a,a+n))
#define SUM(a,n)   (accumulate(a,a+n,0))
#define countbit(x) __builtin_popcount(x)
#define DBG(n)      P("Done %d\n",n);

// I/O
#define I(X)                       scanf("%d", &(X))
#define II(X, Y)                   scanf("%d%d", &(X), &(Y))
#define III(X, Y, Z)               scanf("%d%d%d", &(X), &(Y), &(Z))
#define DI(X) int (X);             scanf("%d", &X)
#define DII(X, Y) int X, Y;        scanf("%d%d", &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)

#define ILL(X)          scanf("%lld", &(X))
#define DILL(X) LL (X); scanf("%lld", &X)

// LOOP
#define repv(i,a) for(int i=0;i<(int)a.size();i++)
#define revv(i,a) for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template <typename T> T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template <typename T> T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template <typename T> T ABS(T a) {if(a<0)return -a;else return a;}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }

int    Set(int N,int pos){ return N=N | (1<<pos);}
int  Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T   togglebit(T a, X i) { T t=1;return (a^(t<<i)); }

int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}

#define VI  vector< int >
#define VII vector< VI >
#define VLL vector< LL >
#define PII pair< int , int >
#define PLL pair< LL , LL >
#define VPI vector< PII >

///         0123456789
#define MX  200007
#define MOD 1000000007
#define INF (1<<30)-1+(1<<30)
#define eps 1e-9

#define base ((1<<l)-1)
#define lft (idx<<1)
#define rgt (lft|1)
#define mid ((l+r)>>1)

/// Hashing Bases & MOD
///           0123456789
#define Base1 10000019ULL
#define Base2 10000079ULL
#define Base3 10000103ULL
#define MOD1  1000000007ULL
#define MOD2  1000000009ULL
#define MOD3  1000000021ULL
#define LOGX  17

char s[MX];

int main(){
    DII(n,k);
    S("%s",s+1);
    set<int> a;

    for (int i=1;i<=n;i++){
        if (s[i] == '4' && s[i+1] == '7')
            a.insert(i);
    }

    while(k-- && !a.empty()){
        int id = *a.begin();
        a.erase(a.begin());

        if (id%2 && s[id+1] == '7' && s[id+2] == '7'){
            if (k%2)   s[id+1] = '4';

            break;
        }

        if (id%2)   s[id+1] = '4';
        else{
            s[id]   = '7';

            if (s[id-1] == '4')     a.insert(id-1);
        }
    }

    P("%s",s+1);
return 0;
}


/*****************************************************************
 *                   BISMILLAHIR RAHMANIR RAHIM                  *
 *          Raihat Zaman Neloy                                   *
 *          JU-CSE-21                                            *
 *          raihatneloy                                          *
 *****************************************************************/

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

#define S scanf
#define P printf

#define  F(i,a,b) for(int i=a;i<b; i++)
#define FF(i,a,b) for(i=a;i<=b;i++)
#define FI(i,a,b) for((typeof(b)) i=a;i<=b;i++)
#define FR(i, a, b,inc) for(  i = (a); i <= (b); i+=inc )
#define RFR(i, a, b,dec) for(  i = (a); i >= (b); i-=dec )
#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;

#define LL long long int
#define ULL unsigned long long int
#define D double

#define Max(a,b)    (a>b?a:b)
#define Min(a,b)    (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n)      (n*n)
#define PI          2.0*acos(0.0)

#define all(a) a.begin(),a.end()
#define X  first
#define Y  second
#define MP make_pair

#define PCC        cout<<"Case "<<cas++<<": ";
#define PC         printf("Case %d:",cas++);
#define PCN        printf("Case %d:\n",cas++);
#define NL         printf("\n");
#define cp         printf("here\n");

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)
#define Case(a)    printf("Case %d:",a)
#define caseh(a)   printf("Case #%d: ",a)
#define S1(a)      scanf("%d",&a)
#define S2(a,b)    scanf("%d%d",&a,&b)
#define S3(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define SL1(a)     scanf("%lld",&a)
#define SL2(a,b)   scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR        getchar()
#define PB(x)      push_back(x)
#define pb         push_back
#define PP         pop_back()
#define PF(x)      push_front(x)
#define PPF(x)     pop_front()
#define PS(x)      push(x)
#define sz()       size()
#define UB         upper_bound
#define LB         lower_bound
#define mxe(a,n)   (*max_element(a,a+n))
#define mne(a,n)   (*min_element(a,a+n))
#define SUM(a,n)   (accumulate(a,a+n,0))
#define countbit(x) __builtin_popcount(x)
#define DBG(n)      P("Done %d\n",n);

// I/O
#define I(X)                       scanf("%d", &(X))
#define II(X, Y)                   scanf("%d%d", &(X), &(Y))
#define III(X, Y, Z)               scanf("%d%d%d", &(X), &(Y), &(Z))
#define DI(X) int (X);             scanf("%d", &X)
#define DII(X, Y) int X, Y;        scanf("%d%d", &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)

#define ILL(X)          scanf("%lld", &(X))
#define DILL(X) LL (X); scanf("%lld", &X)

// LOOP
#define repv(i,a) for(int i=0;i<(int)a.size();i++)
#define revv(i,a) for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template <typename T> T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template <typename T> T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template <typename T> T ABS(T a) {if(a<0)return -a;else return a;}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }

int    Set(int N,int pos){ return N=N | (1<<pos);}
int  Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T   togglebit(T a, X i) { T t=1;return (a^(t<<i)); }

int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}

#define VI  vector< int >
#define VII vector< VI >
#define VLL vector< LL >
#define PII pair< int , int >
#define PLL pair< LL , LL >
#define VPI vector< PII >

///         0123456789
#define MX  200007
#define MOD 1000000007
#define INF (1<<30)-1+(1<<30)
#define eps 1e-9

#define base ((1<<l)-1)
#define lft (idx<<1)
#define rgt (lft|1)
#define mid ((l+r)>>1)

/// Hashing Bases & MOD
///           0123456789
#define Base1 10000019ULL
#define Base2 10000079ULL
#define Base3 10000103ULL
#define MOD1  1000000007ULL
#define MOD2  1000000009ULL
#define MOD3  1000000021ULL
#define LOGX  17

char s[MX];

int main(){
    DII(n,k);
    S("%s",s+1);
    set<int> a;

    for (int i=1;i<=n;i++){
        if (s[i] == '4' && s[i+1] == '7')
            a.insert(i);
    }

    while(k-- && !a.empty()){
        int id = *a.begin();
        a.erase(a.begin());

        if (id%2 && s[id+1] == '7' && s[id+2] == '7'){
            if (!(k%2))   s[id+1] = '4';

            break;
        }

        if (id%2)   s[id+1] = '4';
        else{
            s[id]   = '7';

            if (s[id-1] == '4')     a.insert(id-1);
        }
    }

    P("%s",s+1);
return 0;
}


/*****************************************************************
 *                   BISMILLAHIR RAHMANIR RAHIM                  *
 *          Raihat Zaman Neloy                                   *
 *          JU-CSE-21                                            *
 *          raihatneloy                                          *
 *****************************************************************/

#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

#define S scanf
#define P printf

#define  F(i,a,b) for(int i=a;i<b; i++)
#define FF(i,a,b) for(i=a;i<=b;i++)
#define FI(i,a,b) for((typeof(b)) i=a;i<=b;i++)
#define FR(i, a, b,inc) for(  i = (a); i <= (b); i+=inc )
#define RFR(i, a, b,dec) for(  i = (a); i >= (b); i-=dec )
#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;

#define LL long long int
#define ULL unsigned long long int
#define D double

#define Max(a,b)    (a>b?a:b)
#define Min(a,b)    (a<b?a:b)
#define _Max(a,b,c) Max(a,Max(b,c))
#define _Min(a,b,c) Min(a,Min(b,c))
#define SQR(n)      (n*n)
#define PI          2.0*acos(0.0)

#define all(a) a.begin(),a.end()
#define X  first
#define Y  second
#define MP make_pair

#define PCC        cout<<"Case "<<cas++<<": ";
#define PC         printf("Case %d:",cas++);
#define PCN        printf("Case %d:\n",cas++);
#define NL         printf("\n");
#define cp         printf("here\n");

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)
#define Case(a)    printf("Case %d:",a)
#define caseh(a)   printf("Case #%d: ",a)
#define S1(a)      scanf("%d",&a)
#define S2(a,b)    scanf("%d%d",&a,&b)
#define S3(a,b,c)  scanf("%d%d%d",&a,&b,&c)
#define SL1(a)     scanf("%lld",&a)
#define SL2(a,b)   scanf("%lld%lld",&a,&b)
#define SL3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define CHR        getchar()
#define PB(x)      push_back(x)
#define pb         push_back
#define PP         pop_back()
#define PF(x)      push_front(x)
#define PPF(x)     pop_front()
#define PS(x)      push(x)
#define sz()       size()
#define UB         upper_bound
#define LB         lower_bound
#define mxe(a,n)   (*max_element(a,a+n))
#define mne(a,n)   (*min_element(a,a+n))
#define SUM(a,n)   (accumulate(a,a+n,0))
#define countbit(x) __builtin_popcount(x)
#define DBG(n)      P("Done %d\n",n);

// I/O
#define I(X)                       scanf("%d", &(X))
#define II(X, Y)                   scanf("%d%d", &(X), &(Y))
#define III(X, Y, Z)               scanf("%d%d%d", &(X), &(Y), &(Z))
#define DI(X) int (X);             scanf("%d", &X)
#define DII(X, Y) int X, Y;        scanf("%d%d", &X, &Y)
#define DIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)

#define ILL(X)          scanf("%lld", &(X))
#define DILL(X) LL (X); scanf("%lld", &X)

// LOOP
#define repv(i,a) for(int i=0;i<(int)a.size();i++)
#define revv(i,a) for(int i=((int)a.size())-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)

#define FS(x) for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)

#define MEM(a,val) memset(a,val,sizeof(a));
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

using namespace std;

template <typename T> T BigMod (T b,T p,T m){if (p == 0) return 1;if (p%2 == 0){T s = BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;}
template <typename T> T ModInv (T b,T m){return BigMod(b,m-2,m);}
template <typename T> T in(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9')     break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9')   break;}return (ng?-n:n);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template <typename T> T Bigmod(T b,T p,T m){ if(p==0) return 1; else if (!(p&1)) return SQR(Bigmod(b,p/2,m)) % m;else return ((b % m) * Bigmod(b,p-1,m)) % m;}
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(x1-x2) + SQR(y1-y2) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template <typename T> T DIFF(T a,T b) { T d = a-b;if(d<0)return -d;else return d;}
template <typename T> T ABS(T a) {if(a<0)return -a;else return a;}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template <typename T> void ia (T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> void pa (T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> LL isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }

int    Set(int N,int pos){ return N=N | (1<<pos);}
int  Reset(int N,int pos){return N= N & ~(1<<pos);}
bool Check(int N,int pos){return (bool)(N & (1<<pos));}
template< class T, class X > inline T   togglebit(T a, X i) { T t=1;return (a^(t<<i)); }

int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
int toLlint(string s) { long long int sm; stringstream ss(s); ss>>sm; return sm;}
int cdigittoint(char ch){return ch-'0';}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
bool isConst(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}

double DEG(double x) { return (180.0*x)/(PI);}
double RAD(double x) { return (x*(double)PI)/(180.0);}

#define VI  vector< int >
#define VII vector< VI >
#define VLL vector< LL >
#define PII pair< int , int >
#define PLL pair< LL , LL >
#define VPI vector< PII >

///         0123456789
#define MX  200007
#define MOD 1000000007
#define INF (1<<30)-1+(1<<30)
#define eps 1e-9

#define base ((1<<l)-1)
#define lft (idx<<1)
#define rgt (lft|1)
#define mid ((l+r)>>1)

/// Hashing Bases & MOD
///           0123456789
#define Base1 10000019ULL
#define Base2 10000079ULL
#define Base3 10000103ULL
#define MOD1  1000000007ULL
#define MOD2  1000000009ULL
#define MOD3  1000000021ULL
#define LOGX  17

char s[MX];

int main(){
    DII(n,k);
    S("%s",s+1);
    set<int> a;

    for (int i=1;i<=n;i++){
        if (s[i] == '4' && s[i+1] == '7')
            a.insert(i);
    }

    while(k-- && !a.empty()){
        int id = *a.begin();
        a.erase(a.begin());

        if (id%2 && s[id+1] == '7' && s[id+2] == '7'){
            if (!k%2)   s[id+1] = '4';

            break;
        }

        if (id%2)   s[id+1] = '4';
        else{
            s[id]   = '7';

            if (s[id-1] == '4')     a.insert(id-1);
        }
    }

    P("%s",s+1);
return 0;
}


#include<cstdio>
using namespace std;
int n,k;
char s[100005];
int main(){
	scanf("%d%d",&n,&k);
	getchar();
	scanf("%s",s);
	bool yhb;
	for(int i=1;i<=k;++i){
		yhb=0;
		for(int j=0;j<n;++j){
			if(s[j]=='4'&&s[j+1]=='7'){
				if((j+1)%2==0){
					s[j]=s[j+1]='7';
					yhb=1;break;
				}
				else{
					s[j]=s[j+1]='4';
					yhb=1;break;
				}
			}
		}
		if(!yhb) break;
	}
	printf("%s",s);
}


#include<cstdio>
#define ri register int
using namespace std;
int n,k,pos=0;
char s[100005];

inline int max(int x,int y)
{if(x>y) return x;return y;}
inline int R(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {s=(s<<3)+(s<<1)+ch-'0'; ch=getchar();}
	return s*w;
}
inline void W(int x){
	if(x>=10) W(x/10);
	putchar('0'+x%10);
}

int main(void){
	n=R();k=R();
	scanf("%s",s);
	bool yhb;
	for(ri i=0;i<n&&k;i=max(i,-1),++i){
		if(s[i]=='4'&&s[i+1]=='7'){
			if((i+1)%2==0){
				s[i]=s[i+1]='7';
				i-=2;k--;yhb=1;
			}
			else{
				s[i]=s[i+1]='4';
				i-=2;k--;yhb=1;
			}
		}
	}
	printf("%s",s);
}


#include<cstdio>
#define ri register int
using namespace std;
int n,k;
char s[100005];

inline int R(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {s=(s<<3)+(s<<1)+ch-'0'; ch=getchar();}
	return s*w;
}
inline void W(int x){
	if(x>=10) W(x/10);
	putchar('0'+x%10);
}

int main(void){
	n=R();k=R();
	scanf("%s",s);
	bool yhb;
	for(ri i=1;i<=k;++i){
		yhb=0;
		for(ri j=0;j<n;++j){
			if(s[j]=='4'&&s[j+1]=='7'){
				if((j+1)%2==0){
					s[j]=s[j+1]='7';
					yhb=1;break;
				}
				else{
					s[j]=s[j+1]='4';
					yhb=1;break;
				}
			}
		}
		if(!yhb) break;
	}
	printf("%s",s);
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    string s;cin>>s;
    for(int j=0;j<m;j++){
    for(int i=0;i<s.length();i++){
        string p=s.substr(i,3);
        if(p.find("477")!=-1)m=(m-j)%2;
       if(m==0)break;
        p=s.substr(i,2);
      if(p.find("47")!=-1){if(i%2==1)s.replace(i,2,"77");else s.replace(i,2,"44");break;}
     if(i==s.length()-1)goto em;
    }
    }em:;
    cout<<s;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long n,m;cin>>n>>m;
    string s;cin>>s;
    for(int i=0;i<s.length()&&m;i++){
      if(s[i]=='4'&&s[i+1]=='7'){

        if(i%2==0)s[i]=s[i+1]='4';
        else if(s[i-1]=='4'){ if(m%2==0)s[i]='4';else s[i]='7'; break; }
        else s[i]=s[i+1]='7';
     m--;
      }
    }
    cout<<s;
    return 0;
}


#include <iostream>
#include<algorithm>
#include<fstream>
using namespace std;

int main()
{
 // freopen("C:\\Users\\dell\\Desktop\\rt.txt","r",stdin);
  int n,n1;
while(cin>>n1>>n){
    string s,p="4",p1="7";
    cin>>s;
    for(int j=0;j<n;j++){
    for(int i=0;i<s.length()-1;i++){
      if(s[i]=='4'&&s[i+1]=='7'){
        if(i%2){
          s.erase(i,1);
          s.insert(i,p1);
          break;
        }else{
          s.erase(i+1,1);
          s.insert(i+1,p);
          break;
        }
      }
    }
    }
    cout<<s<<endl;
}
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q;
	cin >> p >> q;
	int tp = p , tq = q;
	if(p % q != 0) {
		cout << p << endl;
		return;
	}
	int ans = 0;
	for(int i = 2;i * i <= tq;i++)  {
		tp = p;
		if(q % i == 0)  {
			while(q % i == 0)  q /= i;
			while(tp % tq == 0) tp /= i;
			ans = max(ans,tp);
		}
	}
	if(q > 1)  {
		while(p % q == 0) p /= q;
		ans = max(ans,p);
	}
	cout << ans << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q;
	cin >> p >> q;
	int tp = p , tq = q;
	if(p % q != 0) {
		cout << p << endl;
		return;
	}
	int ans = 0;
	for(int i = 2;i * i <= tq;i++)  {
		tp = p;
		if(q % i == 0)  {
			while(q % i == 0)  q /= i;
			while(tp % tq == 0) tp /= i;
		}
		ans = max(ans,tp);
	}
	if(q > 1)  {
		while(p % q == 0) p /= q;
	}
	ans = max(ans,p);
	cout << ans << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q;
	cin >> p >> q;
	int best;
	for(int i = 1;i<=sqrt(p);i++)  {
		if(p % i == 0)  {
			if((p / i) % q != 0)  {
				cout << (p / i) << endl;
				return;
			}
			if(i % q != 0)  {
				best = i;
			}
		}
	}
	cout << best << endl;
}

int main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q,i;
	cin >> p >> q;
	if(q > p)  {
		cout << p << endl;
		return;
	}
	for(int i = 1;i<=sqrt(q);i++)  {
		if(p % i == 0)  {
			if((p / i) % q != 0)  {
				cout << (p / i) << endl;
				return;
			}
		}
	}
	cout << (p / (ceil((long double)p / (long double)q) + 1)) << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q,i;
	cin >> p >> q;
	if(q > p)  {
		cout << p << endl;
		return;
	}
	for(int i = 1;i<=sqrt(q);i++)  {
		if(p % i == 0)  {
			if((p / i) % q != 0)  {
				cout << (p / i) << endl;
				return;
			}
		}
	}
	cout << (p / ((p / q) + 1)) << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q;
	cin >> p >> q;
	int best;
	for(int i = 1;i<=sqrt(p);i++)  {
		if(p % i == 0)  {
			if((p / i) % q != 0)  {
				cout << (p / i) << endl;
				return;
			}
			if(i % q != 0)  {
				best = i;
			}
		}
	}
	cout << best << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<cstdint>
#include<stdint.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define int32 int32_t
#define mod 1000000007
#define inf 1000000000000000009
#define mp make_pair
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi std::vector
#define pi std::pair

using namespace std;

void solve() {
	int p,q;
	cin >> p >> q;
	int tp = p , tq = q;
	if(p % q != 0) {
		cout << p << endl;
		return;
	}
	int ans = 0;
	for(int i = 2;i * i <= q;i++)  {
		tp = p;
		if(q % i == 0)  {
			while(q % i == 0)  q /= i;
			while(tp % tq == 0) tp /= i;
		}
		ans = max(ans,tp);
	}
	if(q > 1)  {
		while(p % q == 0) p /= q;
	}
	ans = max(ans,p);
	cout << ans << endl;
}

int32 main()  {
	IOS;
	int t;
	cin >> t;
	for(int i = 1;i<=t;i++)  {
		//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI acos(-1.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define casep cout<<"Case "<<cs++<<": "
///#define endl '\n'
///................function.....................///
#define D(a) (double)(a)
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
int main()
{
    FIO;
    ///freopen("output.txt","r",stdin);
    ///freopen("in.txt","w",stdout);
    t_c
    {
        ll a,b;
        cin>>a>>b;
        if(a%b)
        {
            cout<<a<<endl;
            continue;
        }
        vi prm;
        ll i,j,ans=1LL;
        for(i=2; i*i<=b; i++)
        {
            if(b%i==0)
            {
                prm.pb(i);
                ll tmp=a,res=1;
                b/=i;
                while(b%i==0)
                {
                    b/=i;
                    tmp/=i;
                    res *= i;
                }
                while(tmp%i==0)
                    tmp/=i;
                ans = max(ans,res*tmp);
            }
        }
        if(b>1)
        {
            ans = max(ans, a/b);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI acos(-1.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define casep cout<<"Case "<<cs++<<": "
///#define endl '\n'
///................function.....................///
#define D(a) (double)(a)
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
int main()
{
    FIO;
    ///freopen("output.txt","r",stdin);
    ///freopen("in.txt","w",stdout);
    t_c
    {
        ll a,b;
        cin>>a>>b;
        if(a%b)
        {
            cout<<a<<endl;
            continue;
        }
        vi prm;
        int tmp=b;
        ll i,j,ans=1LL;
        for(i=2; i*i<=tmp; i++)
        {
            if(tmp%i==0)
            {
                prm.pb(i);
                while(tmp%i==0)
                    tmp/=i;
            }
        }
        if(tmp>1)
            prm.pb(tmp);
        for(auto it:prm)
        {
            tmp=b;
            int cnt=0;
            ll res=1LL;
            while(tmp%it==0)
            {
                tmp/=it;
                cnt++;
            }
            cnt--;
            tmp=a;
            while(tmp%it==0)
            {
                tmp/=it;
                if(cnt)
                {
                    cnt--;
                    res*=it;
                }
            }
            ans = max(ans, res*tmp);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI acos(-1.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define casep cout<<"Case "<<cs++<<": "
///#define endl '\n'
///................function.....................///
#define D(a) (double)(a)
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
int main()
{
    FIO;
    ///freopen("output.txt","r",stdin);
    ///freopen("in.txt","w",stdout);
    t_c
    {
        ll a,b;
        cin>>a>>b;
        if(a%b)
        {
            cout<<a<<endl;
            continue;
        }
        vi prm;
        ll i,j,ans=1LL;
        for(i=2; i*i<=b; i++)
        {
            if(b%i==0)
            {
                prm.pb(i);
                ll tmp=a,res=1;
                while(b%i==0)
                {
                    b/=i;
                    tmp/=i;
                    res *= i;
                }
                while(tmp%i==0)
                    tmp/=i;
                res/=i;
                ans = max(ans,res*tmp);
            }
        }
        cout<<ans<<endl;

    }

    return 0;
}