#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;
}
