#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> v(n);

    for(int i = 0; i < q; i++){
        int p, t, x;
        cin >> p;
        if(p == 0){
            cin >> t >> x;
            v[t].push_back(x);
        }
        else if(p == 1){
            cin >> t;
            //vector<int>::iterator itr;
            //itr = v[t].begin();
            int count = 0;
            for(int out : v[t]){
                cout << out;
                count++;
                if(count != v[t].size()){
                    cout << " ";
                }
            }
            cout << endl;
        }
        else {
            cin >> t;
            if(v[t].size() == 0){
                continue;
            }
            else {
                v[t].clear();
            }
        }

        
    }
    return 0;
}
