#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  vector<string> line;
  string li;
  while(getline(cin, li), li != "END_OF_TEXT")
    line.push_back(li);
//  cin.ignore();
  char c;
  int x = 0, y = 0;
  string buf;
  while(cin >> c, c!='-') {
    switch(c) {
    case 'a':
      x=0;
      break;
    case 'e':
      x=line[y].size();
      break;
    case 'p':
      if (y)
        y--;
      x=0;
      break;
    case 'n':
      if (y<line.size()-1)
        y++;
      x=0;
      break;
    case 'f':
      if (x<line[y].size()) {
        x++;
      } else if (y<line.size()-1) {
        y++;
        x=0;
      }
      break;
    case 'b':
      if (x)
        x--;
      else if (y) {
        y--;
        x=line[y].size();
      }
      break;
    case 'd':
      if (x!=line[y].size()) {
        line[y].erase(line[y].begin()+x);
      } else if (y<line.size()-1) {
        line[y] += line[y+1];
        line.erase(line.begin()+y+1);
      }
      break;
    case 'k':
      if (x==line[y].size()) {
        if (y<line.size()-1) {
          line[y] += line[y+1];
          line.erase(line.begin()+y+1);
          buf = "\n";
        }
      } else {
        buf = line[y].substr(x);
        line[y].resize(x);
      }
      break;
    case 'y':
      if (buf=="") break;
      if (buf=="\n") {
        string tmp = line[y].substr(x);
        line[y].resize(x);
        line.insert(line.begin()+y+1,tmp);
        y++;
        x=0;
      } else {
        line[y].insert(x, buf);
        x+=buf.size();
      }
      break;
      
    }
    // cout << c <<  " "  << x << ","<<y<< endl;
    // REP(i, line.size())
    //   cout << i<< ": "<< line[i] << endl;
  }
  FOR(it, line)
    cout << *it << endl;

}