#include <bits/stdc++.h>
using namespace std;
int k, n;
int q;
struct str {
  int a;
  int b;
  bool mi;
};
int const KMAX = 12;
int const BITSETMAX = 4096;
vector<int> input[KMAX];
vector<int> inputTrans[KMAX];
map<pair<int, int>, int> M;
vector<pair<int, int>> queries;
vector<bool> results[KMAX];
vector<str> order;
vector<bitset<BITSETMAX>> creatures;
vector<int> colsIx;
vector<int> cols;
void read() {
  cin >> n >> k >> q;
  for (int i = 0; i < k; i++)
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      input[i].push_back(a);
    }
  for (int i = 0; i < q; i++) {
    int a, b, c;
    cin >> c >> a >> b;
    a--;
    b--;
    if (c == 3) queries.push_back({a, b});
    if (c == 1) order.push_back({a, b, false});
    if (c == 2) order.push_back({a, b, true});
  }
}
void transform() {
  for (int i = 0; i < k; i++) inputTrans[i].resize(n);
  for (int i = 0; i < n; i++) {
    vector<pair<int, int>> v;
    for (int j = 0; j < k; j++) v.push_back({input[j][i], j});
    sort(v.begin(), v.end());
    int val = 0;
    for (int j = 0; j < k; j++) {
      if (j != 0 && v[j - 1] != v[j]) ++val;
      inputTrans[v[j].second][i] = val;
      M[{i, val}] = v[j].first;
    }
  }
}
void solve(int p) {
  creatures.clear();
  colsIx.clear();
  cols.clear();
  for (int i = 0; i < n; i++) {
    int u = 0;
    for (int j = 0; j < k; j++) {
      u *= 2;
      if (inputTrans[j][i] > p) u += 1;
    }
    bool succ = false;
    for (int j = 0; j < cols.size(); j++) {
      if (cols[j] == u) {
        colsIx.push_back(j);
        succ = true;
        break;
      }
    }
    if (!succ) {
      colsIx.push_back(cols.size());
      cols.push_back(u);
    }
  }
  for (int i = 0; i < k; i++) {
    bitset<BITSETMAX> cr;
    for (int j = 0; j < cols.size(); j++) {
      int u = cols[j];
      cr[j] = (u >> (k - 1 - i)) % 2;
    }
    creatures.push_back(cr);
  }
  for (auto &x : order) {
    if (x.mi)
      creatures.push_back(creatures[x.a] & creatures[x.b]);
    else
      creatures.push_back(creatures[x.a] | creatures[x.b]);
  }
  for (int i = 0; i < queries.size(); i++) {
    bool res = creatures[queries[i].first][colsIx[queries[i].second]];
    results[p].push_back(res);
  }
}
int main() {
  ios::sync_with_stdio(0);
  read();
  transform();
  for (int i = 0; i < k - 1; i++) solve(i);
  for (int i = 0; i < queries.size(); i++) {
    int ma = 0;
    for (int j = 0; j < k - 1; j++) {
      if (results[j][i]) ++ma;
    }
    cout << M[{queries[i].second, ma}] << endl;
  }
}
