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

int main() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> a(n, vector<int>(0));
    for (int i = 0; i < q; ++i) {
        int t, d;
        cin >> t >> d;
        if (t == 0) {
            int x;
            cin >> x;
            a[d].push_back(x);
        } else if (t == 1) {
            for (int j = 0; j < a[d].size(); ++j) j == 0 ? cout << a[d][0] : cout << " " << a[d][j];
            cout << endl;
        } else a[d].clear();
    }
}

