#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int n,q;
    cin >> n >> q;
    vector<vector<int>> a(n);
    rep(i ,q){
        int s , t , x;
        cin >> s;
        if ( s == 0 ){
            cin >> t >> x;
            a[t].push_back(x);
        } else if ( s == 1 ){
            cin >> t;
            int j = 0;
            if ( a[t].size() == 0 ) cout << endl;
            else {
                while( j <=(signed int)(a[t].size()-2) )
                    { cout << a[t].at(j) << " "; ++j; }
                if( (signed int)a[t].size() >= 1 ) cout << a[t].at(a[t].size()-1) << endl;
            } 
        } else {
            cin >> t;
            a[t].clear();
        }
    }
    return 0;
}
