#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, moebuta;
cin >> n >> m >> moebuta;
vector<vector<int>> op(m);
for (int i = 0; i < m; i++) {
int c;
cin >> c;
op[i].resize(c);
for (int j = 0; j < c; j++) {
cin >> op[i][j];
op[i][j]--;
}
}
vector<int> t(n);
vector<int> res(n);
iota(res.begin(), res.end(), 0);
for (int i = m - 1; i >= 0; i--) {
fill(t.begin(), t.end(), -1);
int sz = (int) op[i].size();
for (int j = 0; j < sz - 1; j++) {
t[op[i][j]] = op[i][j + 1];
}
if (sz > 1) {
t[op[i][sz - 1]] = op[i][0];
}
for (int i = 0; i < n; i++) {
if (t[res[i]] != -1) {
res[i] = t[res[i]];
}
}
}
for (int i = 0; i < n; i++) {
cout << res[i] + 1 << " \n"[i == n - 1];
}
cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << '\n';
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogIGNpbi50aWUobnVsbHB0cik7CiAgaW50IG4sIG0sIG1vZWJ1dGE7CiAgY2luID4+IG4gPj4gbSA+PiBtb2VidXRhOwogIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gb3AobSk7CiAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgIGludCBjOwogICAgY2luID4+IGM7CiAgICBvcFtpXS5yZXNpemUoYyk7CiAgICBmb3IgKGludCBqID0gMDsgaiA8IGM7IGorKykgewogICAgICBjaW4gPj4gb3BbaV1bal07CiAgICAgIG9wW2ldW2pdLS07CiAgICB9CiAgfQogIHZlY3RvcjxpbnQ+IHQobik7CiAgdmVjdG9yPGludD4gcmVzKG4pOwogIGlvdGEocmVzLmJlZ2luKCksIHJlcy5lbmQoKSwgMCk7CiAgZm9yIChpbnQga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