#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long int
#define lli long long int
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define mk make_pair
#define pb push_back
#define se second
#define fi first
#define nn '\n'
#define lc (id << 1)
#define rc ((id << 1) ^ 1)
#define mid (l + r) / 2
#define txt freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define T int T;cin>>T;while(T--)
#define ashar(x) fixed<<setprecision(x)
#define migmig ios_base::sync_with_stdio(0);cin.tie(0);
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const lli maxn = 5000 + 10, mod = 998244353, sq = 400, lg = 60, inf = 1e9;
ll pw(ll a, ll b) { return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod)); }//a*pw(b,mod-2) == (a/b)%mod
ll n, m, k;
ll cnt[maxn];
vector<ll> v[maxn];
int main(){
ll q;
cin >> n >> m >> q;
ll t, l, r, c, k;
while(q--){
cin >> t;
if(t == 1){
cin >> l >> r >> c >> k;
for(int i = l; i <= r; i++){
v[i].pb(c);
}
}
if(t == 2){
cin >> l >> r >> k;
for(int i = l; i <= r; i++){
if(v[i].size() > cnt[i]) cnt[i]++;
}
}
if(t == 3){
cin >> l >> r;
if(v[l].size() < cnt[l] + r) cout << 0 << nn;
else cout << v[l][cnt[l] + r - 1] << nn;
}
}
}