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

struct Node {
    string val;
    int count;
};

void burstArrayLinear(vector<string>& arr, int k) {
    if (k <= 1) {
        arr.clear();
        return;
    }

    stack<Node> s;

    for (const string& str : arr) {
        // If current matches the top of stack, increase its count
        if (!s.empty() && s.top().val == str) {
            s.top().count++;
        } else {
            // Before pushing a new char, check if the current top should burst
            if (!s.empty() && s.top().count >= k) {
                s.pop();
                // After popping, the NEW top might match the current string
                if (!s.empty() && s.top().val == str) {
                    s.top().count++;
                } else {
                    s.push({str, 1});
                }
            } else {
                s.push({str, 1});
            }
        }
    }

    // Final check for the last remaining element in stack
    if (!s.empty() && s.top().count >= k) {
        s.pop();
    }

    // Reconstruct the array from stack
    vector<string> result;
    vector<Node> temp;
    while (!s.empty()) {
        temp.push_back(s.top());
        s.pop();
    }
    
    // Reverse to get correct order and expand counts
    for (int i = temp.size() - 1; i >= 0; i--) {
        for (int j = 0; j < temp[i].count; j++) {
            result.push_back(temp[i].val);
        }
    }
    arr = result;
}

int main() {
    int n, k;
    cin >> n;
    vector<string> input(n);
    for (int i = 0; i < n; i++) cin >> input[i];
    cin >> k;

    burstArrayLinear(input, k);

    for (const string& s : input) cout << s << endl;

    return 0;
}