#include <bits/stdc++.h>
using namespace std;
signed main() {
  ;
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) {
    int n, m, k;
    cin >> n >> m >> k;
    bool lock[k + 1];
    bool lc[n];
    vector<int> pre[k + 1];
    int mat[n][m];
    int x;
    int res[n];
    memset(lock, false, sizeof(lock));
    memset(lc, false, sizeof(lc));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> mat[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      res[i] = 1000;
    }
    for (int j = 0; j < m; j++) {
      for (int i = 0; i <= k; i++) {
        pre[i].clear();
      }
      for (int i = 0; i < n; i++) {
        if (mat[i][j] == 0 || lc[i]) continue;
        if (lock[mat[i][j]]) {
          res[i] = min(res[i], j + 1);
          lc[i] = 1;
        }
        pre[mat[i][j]].push_back(i);
      }
      for (int i = 0; i <= k; i++) {
        if (pre[i].size() > 1) {
          lock[i] = 1;
          for (int qw = 0; qw < pre[i].size(); qw++) {
            lc[pre[i][qw]] = 1;
            res[pre[i][qw]] = min(res[pre[i][qw]], j + 1);
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (res[i] == 1000)
        cout << "0\n";
      else
        cout << res[i] << "\n";
    }
  };
}
