12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11
12
13
0
1
2
3
4
5
6
7
8
9
10
11^CTraceback (most recent call last):
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py", line 48, in <module>
    main(ptvsdArgs)
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/kenmurata/practice/AtCoder/test.py", line 10, in <module>
    print(j)
KeyboardInterrupt
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63018 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
^CTraceback (most recent call last):
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py", line 48, in <module>
    main(ptvsdArgs)
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/kenmurata/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/kenmurata/practice/AtCoder/test.py", line 10, in <module>
    if int(s[j:j+nagasa]) == tansaku:
KeyboardInterrupt
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63781 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51171 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51236 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51386 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 51967 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52232 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
0
0
0
1
1
0
cbaa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52636 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
0
0
0
1
1
0
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52680 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 52735 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55393 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55498 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aacb
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 55580 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
pca
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 56916 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 57679 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 58073 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
c p
cap
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 58448 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 cp
acp
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 59236 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 cp
acp
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 59555 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
 c
ac
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62327 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cp 
a
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62438 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
cpa
cpa
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62627 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
aabc
(base) bash-3.2$ cd /Users/kenmurata/practice ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /Users/kenmurata/anaconda3/bin/python /Users/kenmurata/.vscode/extensions/ms-python.python-2020.2.64397/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 62684 /Users/kenmurata/practice/AtCoder/test.py < /Users/kenmurata/practice/AtCoder/input.txt 
xy
(base) bash-3.2$ 

### FIXED CODE ###

s = input()
q = int(input())

t = 0
l = ''
r = ''
for i in range(q):
    query = input()
    if query == '1':
        if t == 1:
            t = 0
        else:
            t = 1
    else:
        if query[2] == '1':
            if t == 0:
                l = query[4:]+l
            else:
                r = r+query[4]
        else:
            if t == 0:
                r = r+query[4]
            else:
                l = query[4] + l
s = l+s+r
if t == 1:
    print(s[::-1])
else:
    print(s)