#include <bits/stdc++.h>
using namespace std;
bitset<4096> f[100020];
int a[13][100005], b[100005][13], now;
bool cmp(int x, int y) {
  return a[x][now] == a[y][now] ? x > y : a[x][now] > a[y][now];
}
int main() {
  int n, q, k, cnt, op, x, y;
  scanf("%d%d%d", &n, &k, &q);
  cnt = k;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]), b[j][i] = i;
  for (int i = 1; i <= n; i++) now = i, sort(b[i] + 1, b[i] + k + 1, cmp);
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < (1 << k); j++)
      if (j & (1 << (i - 1))) f[i][j] = 1;
  while (q--) {
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1)
      cnt++, f[cnt] = f[x] | f[y];
    else if (op == 2)
      cnt++, f[cnt] = f[x] & f[y];
    else
      for (int i = 1, t = 0; i <= k; i++) {
        t |= (1 << (b[y][i] - 1));
        if (f[x][t]) {
          printf("%d\n", a[b[y][i]][y]);
          break;
        }
      }
  }
  return 0;
}
