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


int main(){
    int a,b,ch,x,y;
    int ar[6],n=0;
    scanf("%d %d",&a,&b);
    vector<int> v1[a];
    vector<int>:: iterator it;
    for(int k=0;k<b;k++){
        scanf("%d",&ch);

         if (ch==0){
             scanf("%d %d",&x,&y);
             v1[x].push_back(y);
         }
         else if (ch==1){
             scanf("%d",&x);
             
                  for( it=v1[x].begin();it!=v1[x].end();it++){
                         cout << *it;
                         if(it!= v1[x].end()-1)
                        cout <<" ";}
                   cout<<endl;




         }
         else if (ch==2){
                scanf("%d",&x);

                    v1[x].clear();

         }


    }


     return 0;

}

