#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    sum = (sum << 1) + (sum << 3) + (c ^ 48);
    c = getchar();
  }
  return sum;
}
int n, k, true_k, m, a[13][100005];
pair<int, int> b[100005][13];
bitset<4096> c[100005];
int main() {
  n = read(), k = read(), m = read();
  true_k = k;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) {
      a[i][j] = read();
      b[j][i] = make_pair(a[i][j], i);
    }
  for (int i = 1; i <= n; i++) sort(b[i] + 1, b[i] + k + 1);
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < (1 << k); j++)
      if (j & (1 << (i - 1))) c[i][j] = 1;
  while (m--) {
    int opt = read(), x = read(), y = read();
    if (opt == 1) c[++k] = c[x] | c[y];
    if (opt == 2) c[++k] = c[x] & c[y];
    if (opt == 3) {
      int t = 0;
      for (int i = true_k; i >= 1; i--) {
        int pos = b[y][i].second;
        t |= (1 << (pos - 1));
        if (c[x][t]) {
          printf("%d\n", b[y][i].first);
          break;
        }
      }
    }
  }
  return 0;
}
