// AOJ 1021
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

const int LMAX = 1000;

vector<string> lines;
int h, w;
string buffer;

bool on_tail() { return w == lines[h].size(); }
void goto_tail() { w = lines[h].size(); }
bool on_eof() { return h >= lines.size() - 1; }
void remove_line(int n) { lines.erase(lines.begin() + n); }
void remove_char(int h, int w) {
  lines[h].erase(lines[h].begin() + w);
}

void a() { w = 0; }
void e() { goto_tail(); }
void p() { h = max(h - 1, 0); w = 0; }
void n() { h = min(h + 1, (int)lines.size() - 1); w = 0; }
void f() {
  if (not on_tail()) { w++; }
  else if (not on_eof()) {
    h++; w = 0;
  }
}
void b() {
  if (w > 0) { w--; }
  else if (h > 0) { h--; goto_tail(); }
}
void d() {
  if (on_tail() and !on_eof()) {
    lines[h] += lines[h + 1];
    remove_line(h + 1);
  } else if (not on_tail()) {
    remove_char(h, w);
  }
}
void k() {
  if (on_tail() and !on_eof()) {
    d();
    buffer = "\n";
  } else if (not on_tail()) {
    buffer = lines[h].substr(w);
    lines[h] = lines[h].substr(0, w);
  }
}
void y() {
  if (buffer == "\n") {
    string temp = lines[h].substr(w);
    lines[h] = lines[h].substr(0, w);
    lines.insert(lines.begin() + h + 1, temp);
    h++; w = 0;
  } else if (not buffer.empty()) {
    lines[h].insert(lines[h].begin()+w, buffer.begin(), buffer.end());
    w += buffer.size();
  }
}

int main() {
  string l;
  buffer = "";
  while (getline(cin, l) and l != "END_OF_TEXT") {
    lines.push_back(l);
  }

  char com;
  while (cin >> com and com != '-') {
    switch (com) {
    case 'a':
      a(); break;
    case 'e':
      e(); break;
    case 'p':
      p(); break;
    case 'n':
      n(); break;
    case 'f':
      f(); break;
    case 'b':
      b(); break;
    case 'd':
      d(); break;
    case 'k':
      k(); break;
    case 'y':
      y(); break;
    default:
      break;
    }
/*    REP(i, lines.size()) {
      cout << ">" << lines[i] << endl;
    }
    cout << "(" << h << "," << w << ")" << endl;
*/  }

  for (int i = 0; i < lines.size(); i++) {
    cout << lines[i] << endl;
  }
}