#include <bits/stdc++.h>
const int N = 1e5 + 5, K = 13;
int n, m, k, q, ans, a[K][N];
std::bitset<1 << K> f[N];
int main() {
  scanf("%d%d%d", &n, &k, &q), m = k;
  int i, j, o, x, y;
  for (i = 1; i <= k; i++)
    for (j = 1; j <= n; j++) scanf("%d", a[i] + j);
  for (i = 1; i <= k; i++)
    for (j = 0; j < 1 << k; j++) f[i][j] = j >> i - 1 & 1;
  while (q--)
    if (scanf("%d%d%d", &o, &x, &y), o < 2)
      f[++m] = f[x] | f[y];
    else if (o < 3)
      f[++m] = f[x] & f[y];
    else {
      for (ans = 0, i = 1; i <= k; i++) {
        for (o = 0, j = 1; j <= k; j++) o |= (a[j][y] >= a[i][y]) << j - 1;
        if (f[x][o]) ans = std::max(ans, a[i][y]);
      }
      printf("%d\n", ans);
    }
  return 0;
}
