#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 101000;
bitset<4096> q[N];
vector<pair<int, int> > v[N];
int n, k, Q, ty, p1, p2, w, b[20][N];
int main() {
  scanf("%d%d%d", &n, &k, &Q);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++)
      scanf("%d", &b[i][j]), v[j].push_back(make_pair(b[i][j], i));
    for (int j = 0; j < 4096; j++) q[i][j] = (j >> i) & 1;
  }
  for (int j = 0; j < n; j++) sort((v[j]).begin(), (v[j]).end());
  w = k;
  for (int i = 0; i < Q; i++) {
    scanf("%d%d%d", &ty, &p1, &p2);
    --p1;
    --p2;
    if (ty != 3) {
      if (ty == 1)
        q[w++] = (q[p1] | q[p2]);
      else
        q[w++] = (q[p1] & q[p2]);
    } else {
      int s = 0;
      for (int j = k - 1; j >= 0; j--) {
        s |= (1 << v[p2][j].second);
        if (q[p1][s]) {
          printf("%d\n", v[p2][j].first);
          break;
        }
      }
    }
  }
}
