#include <iostream>
#include <vector>

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

