#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) struct S { int P[18]; }; S op(S l, S r) { rep(i,18) l.P[i] = r.P[l.P[i]]; return l; } S e() { S res; rep(i,18) res.P[i] = i; return res; } using RQ = atcoder::segtree; int main(){ int N,M,Q; cin >> N >> M >> Q; RQ G(M); while(Q--){ int t; cin >> t; if(t == 1){ int d; cin >> d; d--; S v = e(); rep(i,N){ cin >> v.P[i]; v.P[i]--; } G.set(d,v); } if(t == 2){ int d; cin >> d; S res = G.prod(0,d); int ans[18]; rep(i,N) ans[res.P[i]] = i + 1; rep(i,N){ if(i != 0) cout << " "; cout << ans[i]; } cout << "\n"; } if(t == 3){ int l,r; cin >> l >> r; l--; S res = G.prod(l,r); int ans = 0; rep(i,N) ans += abs(i-res.P[i]); cout << ans << "\n"; } } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;