#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, m, opt, x, y, cnt, a[15][N];
bitset<5000> s[N];
struct node {
  int val, id;
  friend bool operator<(node a, node b) { return a.val > b.val; }
};
int main() {
  scanf("%d%d%d", &n, &k, &m);
  cnt = k;
  for (int i = 1; i <= k; i++) {
    for (int j = 0; j < (1 << k); j++)
      if (j & (1 << (i - 1))) s[i].set(j);
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  }
  while (m--) {
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) s[++cnt] = s[x] | s[y];
    if (opt == 2) s[++cnt] = s[x] & s[y];
    if (opt == 3) {
      vector<node> v;
      for (int i = 1; i <= k; i++) v.push_back((node){a[i][y], i});
      sort(v.begin(), v.end());
      int sum = 0;
      for (int i = 0; i < k; i++) {
        sum |= (1 << (v[i].id - 1));
        if (s[x][sum]) {
          printf("%d\n", v[i].val);
          break;
        }
      }
    }
  }
  return 0;
}
