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

int main(){
  string txt[110],str,buf;
  char c;
  int x,y;

  y = 0;
  while(1){
    getline(cin,str);
    if(str == "END_OF_TEXT")break;
    txt[y] = str + '\n';
    y++;
  }

  x = y = 0;
  while(1){
    c = getchar();
    if(c == '-')break;
    if(c == 'a'){
      x = 0;
    }
    if(c == 'e'){
      x = (int)txt[y].size() - 1;
    }
    if(c == 'p'){
      if(y){
	y--;
	x = 0;
      }else x = 0;
    }
    if(c == 'n'){
      if(txt[y+1].size()){
	y++;
	x = 0;
      }else x = 0;
    }
    if(c == 'f'){
      if(x != (int)txt[y].size() - 1)x++;
      else if(txt[y+1].size()){
	y++;
	x = 0;
      }
    }
    if(c == 'b'){
      if(x)x--;
      else if(y){
	y--;
	x = (int)txt[y].size() - 1;
      }
    }
    if(c == 'd'){
      if(txt[y][x] != '\n'){
	txt[y].erase(txt[y].begin()+x);
      }else if(txt[y+1].size()){
	txt[y].erase(txt[y].begin()+x);
	txt[y] += txt[y+1];
	int tmp = y+1;
	while(txt[tmp+1].size()){
	  txt[tmp] = txt[tmp+1];
	  tmp++;
	}
	txt[tmp].clear();
      }
    }
    if(c == 'k'){
      if(x == (int)txt[y].size() - 1){
	if(txt[y+1].size()){
	  txt[y].erase(txt[y].begin()+x);
	  txt[y] += txt[y+1];
	  int tmp = y+1;
	  while(txt[tmp+1].size()){
	    txt[tmp] = txt[tmp+1];
	    tmp++;
	  }
	  txt[tmp].clear();
	  buf = '\n';
	}
      }else{
	buf.clear();
	while(txt[y][x] != '\n'){
	  buf.push_back(txt[y][x]);
	  txt[y].erase(txt[y].begin()+x);
	}
      }
    }
    if(c == 'y'){
      if(buf.size()){
	if(buf == "\n"){
	  int tmp = y+1;
	  str = txt[y+1];
	  txt[y+1].clear();
	  while(txt[y][x] != '\n'){
	    txt[y+1].push_back(txt[y][x]);
	    txt[y].erase(txt[y].begin()+x);
	  }
	  txt[y+1].push_back('\n');
	  while(txt[++tmp].size())swap(txt[tmp],str);
	  txt[tmp] = str;
	  y++;
	  x = 0;
	}else{
	  str.clear();
	  for(int i=0;i<x;i++)str.push_back(txt[y][i]);
	  str += buf;
	  for(int i=x;i<(int)txt[y].size();i++)str.push_back(txt[y][i]);
	  txt[y] = str;
	  x += buf.size();
	}
      }
    }
    //cout << c << ":" << y << " " << x << endl;
    getchar();
  }
  y = 0;
  while(txt[y].size())cout << txt[y++];
}