#include <bits/stdc++.h>
using namespace std;
const int K = 12, N = 1e5 + 5, Z = 1 << K;
vector<int> val[N], cr[K], cr2[K];
bitset<Z> b[N + K];
int mk[N * K];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, k, q;
  cin >> n >> k >> q;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      val[j].push_back(x);
      cr[i].push_back(x);
    }
  }
  for (int i = 0; i < n; i++) {
    sort(val[i].begin(), val[i].end());
  }
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) {
      int y =
          lower_bound(val[j].begin(), val[j].end(), cr[i][j]) - val[j].begin();
      for (int h = 0; h < k; h++) cr2[i].push_back(h < y ? 1 : 0);
    }
  }
  for (int i = 0; i < n * k; i++) {
    for (int j = 0; j < k; j++) {
      mk[i] |= cr2[j][i] << j;
    }
    for (int j = 0; j < k; j++) {
      b[j][mk[i]] = cr2[j][i];
    }
  }
  for (int i = 0, j = k; i < q; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    x--, y--;
    if (t == 1) {
      b[j] = (b[x] | b[y]);
      j++;
    } else if (t == 2) {
      b[j] = (b[x] & b[y]);
      j++;
    } else {
      int p = y * k;
      while (b[x][mk[p]]) p++;
      cout << val[y][p % k] << "\n";
    }
  }
  return 0;
}
