#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

void insetrtionsort(int a[], int n)
{
    int j, v;
    for (int i = 1; i < n; i++)
    {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

int gcd(int a, int b)
{
    if (a < b)
    {
        int t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << endl;
    if (b == 0) return a;
    else return gcd(b, b%a);
}

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

