/*
 * Author: Dumbear
 * Created Time:  2011/8/31 14:59:27
 * File Name: 
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <list>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

vector<string> text;
int cx, cy;
string buffer;

void a() {
    cy = 0;
}

void e() {
    cy = text[cx].size();
}

void p() {
    if (cx == 0)
        cy = 0;
    else {
        --cx;
        cy = 0;
    }
}

void n() {
    if (cx + 1 == text.size())
        cy = 0;
    else {
        ++cx;
        cy = 0;
    }
}

void f() {
    if (cy != text[cx].size())
        ++cy;
    else if (cx + 1 != text.size()) {
        ++cx;
        cy = 0;
    }
}

void b() {
    if (cy != 0)
        --cy;
    else if (cx != 0) {
        --cx;
        cy = text[cx].size();
    }
}

void d() {
    if (cy != text[cx].size())
        text[cx].erase(text[cx].begin() + cy);
    else if (cx + 1 != text.size()) {
        text[cx] += text[cx + 1];
        text.erase(text.begin() + cx + 1);
    }
}

void k() {
    if (cy != text[cx].size()) {
        buffer = text[cx].substr(cy);
        text[cx].erase(cy);
    } else if (cx + 1 != text.size()) {
        d();
        buffer = "\n";
    }
}

void y() {
    if (buffer.empty())
        return;
    if (buffer == "\n") {
        text.insert(text.begin() + cx + 1, text[cx].substr(cy));
        text[cx].erase(cy);
        ++cx;
        cy = 0;
    } else {
        text[cx].insert(cy, buffer);
        cy += buffer.size();
    }
}

void solve();

int main() {
    solve();
    return 0;
}

void solve() {
    while (true) {
        string buf;
        char c;
        while ((c = getchar()) != EOF) {
            if (c == '\n')
                break;
            buf += c;
        }
        if (c == EOF)
            while (1);
        if (buf == "END_OF_TEXT")
            break;
        text.push_back(buf);
    }
    if (text.empty())
        while (1);
    cx = cy = 0;
    buffer.clear();
    while (true) {
        string buf;
        char c;
        while ((c = getchar()) != EOF) {
            if (c == '\n')
                break;
            buf += c;
        }
        if (c == EOF)
            while (1);
        if (buf == "-")
            break;
        switch (buf[0]) {
            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:
                while (1);
                break;
        }
    }
    for (vector<string>::iterator i = text.begin(); i != text.end(); ++i)
        puts(i->c_str());
}

Measured memory_bytes: 0