#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, q; cin >> n >> q;
	VI x(q), y(q), z(q);
	vector<VI> a(n);
	rep(i, q) {
		cin >> x[i];
		if (x[i] == 0)cin >> y[i] >> z[i];
		else cin >> y[i];
	}

	rep(i, q) {
		if (x[i] == 0) {
			a[y[i]].pb(z[i]);
		}
		else if (x[i] == 1) {
			rep(j, SZ(a[y[i]])) {
				cout << a[y[i]][j];
				if (j != SZ(a[y[i]]) - 1)cout << " ";
			}
			puts("");
		}
		else if (x[i] == 2) {
			if (!a[y[i]].empty())a[y[i]].clear();
		}
	}
}
