#include <bits/stdc++.h>
using namespace std;
const int magic = (int)1e6;
void solve(int n) {
  int k, q;
  cin >> k >> q;
  vector<vector<int>> a(k, vector<int>(n));
  for (int i = 0; i < (int)(k); ++i)
    for (int j = 0; j < (int)(n); ++j) cin >> a[i][j];
  vector<vector<int>> sorted_skills(n, vector<int>(k));
  for (int i = 0; i < (int)(k); ++i)
    for (int j = 0; j < (int)(n); ++j) sorted_skills[j][i] = a[i][j];
  for (int i = 0; i < (int)(n); ++i)
    sort((sorted_skills[i]).begin(), (sorted_skills[i]).end());
  vector<int> t(q), x(q), y(q);
  int quest = 0;
  vector<int> what_quest;
  for (int i = 0; i < (int)(q); ++i) {
    cin >> t[i] >> x[i] >> y[i];
    --x[i], --y[i];
    quest += (t[i] == 3);
    if (t[i] == 3) what_quest.push_back(y[i]);
  }
  vector<int> qans(quest);
  for (int beats = 0; beats < (int)(k); ++beats) {
    vector<int> type(n);
    for (int i = 0; i < (int)(k); ++i)
      for (int j = 0; j < (int)(n); ++j)
        if (a[i][j] > sorted_skills[j][beats]) type[j] |= (1 << i);
    int h = k, curquest = 0;
    const int maxt = (1 << 12);
    vector<bitset<maxt>> cmp(k + q);
    for (int i = 0; i < (int)(k); ++i)
      for (int ntype = 0; ntype < (int)((1 << k)); ++ntype)
        cmp[i][ntype] = ((ntype >> i) & 1);
    for (int it = 0; it < (int)(q); ++it) {
      if (t[it] == 1)
        cmp[h++] = cmp[x[it]] | cmp[y[it]];
      else if (t[it] == 2)
        cmp[h++] = cmp[x[it]] & cmp[y[it]];
      else if (t[it] == 3) {
        if (cmp[x[it]][type[y[it]]]) {
          assert(qans[curquest] == beats);
          qans[curquest]++;
          curquest++;
        } else
          curquest++;
      } else
        assert(false);
    }
  }
  for (int i = 0; i < (int)(quest); ++i) {
    assert(0 <= qans[i] && qans[i] < k);
    cout << sorted_skills[what_quest[i]][qans[i]] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  while (cin >> n) solve(n);
}
