#include <bits/stdc++.h>
using namespace std;
const int N = 1'000'007;
int p[N], pos[N];
long long pref[N];
void move(int x){
int ps = pos[x];
swap(p[ps], p[ps - 1]);
pos[p[ps]] = ps;
pos[p[ps - 1]] = ps - 1;
pref[ps - 1] = pref[ps - 2] + p[ps - 1];
pref[ps] = pref[ps - 1] + p[ps];
}
int main()
{
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> p[i];
pos[p[i]] = i;
}
pref[0] = 0;
for(int i = 1; i <= n; i++){
pref[i] = pref[i - 1] + p[i];
}
int q;
cin >> q;
for(int query = 0; query < q; query++){
int t;
cin >> t;
if(t == 1){
int k;
cin >> k;
for(int i = 0; i < k; i++){
move(1);
}
}
else if(t == 2){
int x;
cin >> x;
move(x);
}
else{
int x, k;
cin >> x >> k;
int l = pos[x] - k;
int r = pos[x] - 1;
cout << pref[r] - pref[l - 1] << "\n";
}
}
return 0;
}