#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int x, y,a,b,c; cin >> x >> y;
	vector<vector<int>> v(x, vector<int>());
	for (int i = 0; i < y; i++) {
		cin >> a >> b;
		if (a == 0) {
			cin >> c;
			v[b].push_back(c);
		}
		else if (a == 1) {
			for (int j = 0; j < v[b].size();j++) {
				if (j) {
					cout << ' ';
				}
				 cout << v[b][j];
			}
			cout << endl;
		}
		else {
			v[b].clear();
		}
	}
}

