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

int main(void){
	int n,q,x,y;
	cin>>n>>q;
	vector<int> v[n];
	while(q--){
		cin>>x;
		if(x==0){
			//pb
			cin>>x>>y;
			v[x].push_back(y);
		}else if(x==1){
			cin>>x;
			for(int i=0;i<v[x].size();i++){
				if(i!=0)cout<<" ";
				cout<<v[x][i];
			}
			cout<<endl;
		}else{
			cin>>x;
			v[x].clear();
		}
	}
	return 0;
}

