#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f |= ch == '-', ch = getchar();
  while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
  return f ? -x : x;
}
const int N = 100015;
vector<pair<int, int> > kind[N];
int sz;
typedef struct _bitset {
  long long data[70];
  _bitset() { memset(data, 0, sizeof(data)); }
  friend _bitset operator|(const _bitset &a, const _bitset &b) {
    _bitset c;
    for (register int i = 0; i <= sz; i++) c.data[i] = a.data[i] | b.data[i];
    return (c);
  }
  friend _bitset operator&(const _bitset &a, const _bitset &b) {
    _bitset c;
    for (register int i = 0; i <= sz; i++) c.data[i] = a.data[i] & b.data[i];
    return (c);
  }
  inline int test(int b) { return ((data[b / 64] & (1ull << (b & 63))) != 0); }
  inline void set(int b) { data[b / 64] |= (1ull << (b & 63)); }
} bitfuck;
bitfuck f[N];
int n, k, q, len;
int main() {
  n = read(), k = read(), q = read();
  sz = (1 << k) / 64 + 1;
  for (register int i = 0; i <= k - 1; i++) {
    for (register int j = 0; j <= n - 1; j++) {
      int x = read();
      kind[j].push_back(make_pair(x, i));
    }
    for (register int j = 0; j <= (1 << k) - 1; j++) {
      if (j >> i & 1) f[i].set(j);
    }
  }
  for (register int i = 0; i <= n - 1; i++) {
    sort(kind[i].begin(), kind[i].end(), greater<pair<int, int> >());
  }
  int len = k;
  while (q--) {
    int opt = read(), x = read(), y = read();
    x--, y--;
    if (opt == 1) {
      f[len] = f[x] | f[y];
      len++;
    } else if (opt == 2) {
      f[len] = f[x] & f[y];
      len++;
    } else {
      int s = 0;
      for (auto v : kind[y]) {
        s |= 1 << v.second;
        if (f[x].test(s)) {
          printf("%d\n", v.first);
          break;
        }
      }
    }
  }
  return 0;
}
