#include <iostream>
#include <stack>
using namespace std;
class LinkedList {
private:
struct node {
int value;
node* next;
};
node *first;
node *p;
node *q;
public:
LinkedList();
void add(int value);
void print();
void query(int position);
void insert(int position, int value);
void remove(int position);
void reverse(int i, int j);
int getValue(int position);
};
LinkedList::LinkedList() {
first = NULL; p = NULL; q = NULL;
}
void LinkedList::add(int value) {
node* n = new node;
n->next = first;
n->value = value;
if (first != NULL) {
p = first;
while (p->next != NULL && p->next != first) p = p->next;
p->next = n;
}
else first = n;
}
void LinkedList::print() {
p = first;
(p->value < 10) ? cout << "0" << p->value << " " : cout << p->value << " ";
p = p->next;
while (p != first) {
(p->value < 10) ? cout << "0" << p->value << " " : cout << p->value << " ";
p = p->next;
}
cout << endl;
}
void LinkedList::query(int position) {
p = first;
for (int i = 0; i < position - 1; i++) p = p->next;
cout << p->value << endl;
}
int LinkedList::getValue(int position) {
p = first;
for (int i = 0; i < position - 1; i++) p = p->next;
return p->value;
}
void LinkedList::insert(int position, int value) {
node* n = new node;
n->value = value;
p = first;
for (int i = 0; i < position - 1; i++) p = p->next;
n->next = p->next;
p->next = n;
}
void LinkedList::remove(int position) {
node * n = NULL;
p = first;
if (position == 1) first = first->next;
else {
for (int i = 0; i < position - 1; i++)
{
q = p;
p = p->next;
}
n = p;
p = p->next;
q->next = p;
delete n;
}
}
void LinkedList::reverse(int i, int j) {
stack <int> temp;
for (int k = i; k < j; k++) {
temp.push(getValue(i));
remove(i);
}
for (int k = i; k < j; k++) {
insert(k, temp.top());
temp.pop();
}
}
int main() {
LinkedList list;
int N;
cin >> N;
for (int size = 0; size < N; size++)
{
int value;
cin >> value;
list.add(value);
}
int Q, ref = 1;
cin >> Q;
for (int time = 0; time < Q; time++) {
int command, position, value;
cin >> command >> position;
ref += position - 1;
switch (command)
{
case 1:
cin >> value;
list.insert(ref++, value);
N++;
break;
case 2:
list.remove(ref--);
N--;
break;
case 3:
list.query(ref);
break;
case -1:
return 0;
default:
break;
}
ref %= N; if (ref == 0)ref = N;
//list.print();
//for (int i = 1; i < ref%N; i++) cout << " "; cout << ref << " size " << N << endl;
}
return 0;
}