#include <iostream>
#include <cstring>

using namespace std;

struct vector2 {
    int cap = 128;
    int *data;
    int pos = 0;

    vector2() {
        data = new int[cap];
    }
};

void pushBack(vector2 &t, int x) {
    if (t.pos == t.cap) {
        t.cap *= 2;
        int *new_data = new int[t.cap];
        memcpy(new_data, t.data, t.pos * sizeof(int));
        delete[] t.data;
        t.data = new_data;
    }
    t.data[t.pos++] = x;
}

void dump(vector2 &t) {
    if (t.pos > 0) {
        for (int i = 0; i < t.pos; i++) {
            cout << (i == 0 ? "" : " ");
            cout << t.data[i];
        }
    }
    cout << endl;
}

void clear(vector2 &t) {
    t.pos = 0;
}

int main() {
    int n, Q;
    cin >> n >> Q;

    vector2 A[n];

    while (Q--) {
        int q, t, x;
        cin >> q;
        switch (q) {
            case 0:
                cin >> t >> x;
                pushBack(A[t], x);
                break;
            case 1:
                cin >> t;
                dump(A[t]);
                break;
            case 2:
                cin >> t;
                clear(A[t]);
                break;
        }
    }
}

