n = int(input())
p = list(map(int, input().split()))
pos = [0] * (n + 1)
pref = [0] * (n + 1)
for i in range(n):
pos[p[i]] = i
pref[i + 1] = pref[i] + p[i]
q = int(input())
for _ in range(q):
query = list(map(int, input().split()))
if query[0] == 1:
for i in range(query[1]):
ps = pos[1]
p[ps - 1], p[ps] = p[ps], p[ps - 1]
pos[p[ps - 1]] = ps - 1
pos[p[ps]] = ps
pref[ps] = pref[ps - 1] + p[ps - 1]
elif query[0] == 2:
ps = pos[query[1]]
p[ps - 1], p[ps] = p[ps], p[ps - 1]
pos[p[ps - 1]] = ps - 1;
pos[p[ps]] = ps;
pref[ps] = pref[ps - 1] + p[ps - 1]
else:
l = (pos[query[1]] + 1) - query[2]
r = (pos[query[1]] + 1) - 1
print(pref[r] - pref[l - 1]);