Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N, M, Q = map(int, input().split())

N_Map = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

Li = []
for _ in range(M):
    a = list(map(int, input().split()))
    Li.append(a)
    N_Map[a[0]][a[1]] += 1

Pi = []
for _ in range(Q):
    a = list(map(int, input().split()))
    Pi.append(a)

for p in Pi:
    ans = 0
    for i in range(p[0], p[1] + 1):
        for j in range(p[0], p[1] + 1):
            ans += N_Map[i][j]
    print(ans)


### FIXED CODE ###

N, M, Q = map(int, input().split())
N_Map = [[0 for _ in range(N + 1)] for _ in range(N + 1)]

for _ in range(M):
    a = list(map(int, input().split()))
    N_Map[a[0]][a[1]] += 1

for i in range(N, 0, -1):
    count = 0
    for j in range(1, N  + 1):
        count += N_Map[i][j]
        if i < N:
            N_Map[i][j] = N_Map[i + 1][j] + count
        else:
            N_Map[i][j] = count

Pi = []
for _ in range(Q):
    a = list(map(int, input().split()))
    Pi.append(a)

for p in Pi:
    print(N_Map[p[0]][p[1]])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
	
def main():
	N, M, Q = map(int, input().split(" "))
	
	LR = []
	for _ in range(M):
		l, r = map(int, input().split(" "))
		LR.append((l, r))
		
	PQ = []
	for _ in range(Q):
		p, q = map(int, input().split(" "))
		PQ.append((p, q))
	
	ans = []
	for i in PQ:
		p, q = i
		tmp = 0
		for j in LR:
			l, r = j
			if p <= l and r <= q:
				tmp += 1
		ans.append(tmp)
	
	for i in ans:
		print(i)
	
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np

def main():
	N, M, Q = map(int, input().split(" "))
	N_list = [[0 for _ in range(N)] for _ in range(N)]
	
	for _ in range(M):
		l, r = map(int, input().split(" "))
		l -= 1
		r -= 1
		N_list[l][r] += 1
		
	#print(N_list)
	
	for i in range(N):
		for j in range(N):
			if i == 0 and j == 0:
				continue
			if i == 0:
				N_list[i][j] = N_list[i][j] + N_list[i][j-1]
				continue
			if j == 0:
				N_list[i][j] = N_list[i][j] + N_list[i-1][j]
				continue
			N_list[i][j] = N_list[i][j] + N_list[i-1][j] + N_list[i][j-1] - N_list[i-1][j-1]
			
	#print(N_list)
		
	for _ in range(Q):
		p, q = map(int, input().split(" "))
		p -= 1
		q -= 1
		
		a = 0
		b = 0
		c = 0
		if p != 0:
			a = N_list[q][p-1]
			b = N_list[p-1][q]
			c = N_list[p-1][p-1]
		ans = N_list[q][q] - a - b + c
		print(ans)
		
	
if __name__ == "__main__":
	main()
### BUGGY CODE ###

if __name__ == "__main__":
	a, b, c, k = map(int, input().strip().split(' '))
	s = 0
	for i in range(k):
		if a > 0:
			s += 1
			a -= 1
		elif b > 0:
			b -= 1
		elif c > 0:
			s -= 1
			c -= 1
	print(s)

### FIXED CODE ###

if __name__ == "__main__":
	a, b, c, k = map(int, input().strip().split(' '))
	s, i = 0, 0
	if k <= a:
		s = k
	elif k > a:
		s = a
		k -= a
		if k > b:
			k -= b
			s -= k
	print(s)
### BUGGY CODE ###

class UnionFindTree():
  def __init__(self,n):
    self.parent = []
    self.rank = []
    for i in range(n):
      self.parent.append(i)
      self.rank.append(int(1))

  def find(self,n):
    if self.parent[n] == n:
      return self.parent[n]
    else:
      self.parent[n] = self.find(self.parent[n])
      return self.parent[n]

  def unite(self,n,m):
    n = self.find(n)
    m = self.find(m)

    if n == m:
      return
    else:
      if self.rank[n] < self.rank[m]:
        self.parent[n] = m
      elif self.rank[n] > self.rank[m]:
        self.parent[m] = n
      elif self.rank[n] == self.rank[m]:
        self.parent[m] = n
        self.rank[n] += 1




N,M,K = (int(i) for i in input().split())

uft = UnionFindTree(N)

friend = [0] * N
for i in range(M):
  A,B = (int(i) for i in input().split())
  uft.unite(A-1,B-1)
  friend[A-1] += 1
  friend[B-1] += 1


# candidate = [4,3,1]
# candidate => 自分 + 友達 + 友達候補 (include ブロック関係)
for i in range(N):
  uft.find(i)

candidate = []
for i in range(N):
  candidate.append(uft.parent.count(uft.parent[i]))

blocked = [0] * N
for i in range(K):
  C,D = (int(i) for i in input().split())
  if uft.parent[C-1] == uft.parent[D-1]:
    blocked[C-1] += 1
    blocked[D-1] += 1

for i in range(N):
  candidate[i] -= (friend[i]+blocked[i]+1)


print(*candidate)



### FIXED CODE ###

class UnionFindTree():
  def __init__(self,n):
    self.parent = []
    self.rank = []
    self.candidate = []
    for i in range(n):
      self.parent.append(i)
      self.rank.append(int(1))
      self.candidate.append(int(1))

  def find(self,n):
    if self.parent[n] == n:
      return self.parent[n]
    else:
      self.parent[n] = self.find(self.parent[n])
      return self.parent[n]

  def unite(self,n,m):
    n = self.find(n)
    m = self.find(m)

    if n == m:
      return
    else:
      if self.rank[n] < self.rank[m]:
        self.parent[n] = m
        self.candidate[m] += self.candidate[n]
      elif self.rank[n] > self.rank[m]:
        self.parent[m] = n
        self.candidate[n] += self.candidate[m]
      elif self.rank[n] == self.rank[m]:
        self.parent[m] = n
        self.candidate[n] += self.candidate[m]
        self.rank[n] += 1




N,M,K = (int(i) for i in input().split())

uft = UnionFindTree(N)

friend = [0] * N
for i in range(M):
  A,B = (int(i) for i in input().split())
  uft.unite(A-1,B-1)
  friend[A-1] += 1
  friend[B-1] += 1


# candidate = [4,3,1]
# candidate => 自分 + 友達 + 友達候補 (include ブロック関係)
candidate = []
for i in range(N):
  candidate.append(uft.candidate[uft.find(i)])

blocked = [0] * N
for i in range(K):
  C,D = (int(i) for i in input().split())
  if uft.parent[C-1] == uft.parent[D-1]:
    blocked[C-1] += 1
    blocked[D-1] += 1

for i in range(N):
  candidate[i] -= (friend[i]+blocked[i]+1)


print(*candidate)
### BUGGY CODE ###

n,k = map(int,input().split()) 
 #複数文字の入力
ans = 0     
for i in range(n+1):
  j=0
  #カウンター設置
  while i<k:
    i*=2
    j+=1
  ans=1/2**j
print(ans/n)

### FIXED CODE ###

n,k = map(int,input().split()) 
 #複数文字の入力
ans = 0

for i in range(1,n+1):
  j=0 
  #カウンター設置
  while i<k:
    i*=2
    j+=1
  ans+=1/2**j
print("{:.12}".format(ans/n))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))

mod=10**9+7
sum=0
for i in range(N-1):
    for j in range(i+1,N):
        A[i]=A[i]%mod
        A[j]=A[j]%mod
        sum+=((A[i])*(A[j] ))
print(sum%mod)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))

mod=10**9+7

B=[0]
for i in range(1,N+1):
    B.append(A[i-1]+B[i-1])

ans=0
for i in range(N-1):
    ans+=A[i]*(B[N]-B[i+1])
    ans%=mod

print(int(ans))
### BUGGY CODE ###

from itertools import combinations
N = int(input())
s = input()
ans = set()
for i in combinations(s,3):
    ans.add(i)
print(len(ans))

### FIXED CODE ###

from itertools import combinations
N = int(input())
s = input()
ans = 0
for a2 in range(10):
    for b2 in range(10):
        for c2 in range(10):
            a = str(a2)
            b = str(b2)
            c = str(c2)
            count = 0
            for i in s:
                if a == i:
                    count += 1
                    if count == 1:
                        a = b
                    if count == 2:
                        a = c
            if count >= 3:
                ans += 1
print(ans)
### BUGGY CODE ###

import sys

def count_prime(x):
    temp = 0
    if(x > 2):
        temp += 1
    for i in range(3,x+1,2):
        if(i % 2 == 0):
            continue
        for j in range(3,i+1,2):
            if(j == i):
                temp += 1
            elif(i % j == 0):
                break
    return temp

l = []
for input in sys.stdin:
    l.append(input)
print l
for input in l:
    print count_prime(int(input))


### FIXED CODE ###

import sys

def is_prime(x):
    if(x <= 3 and x > 1):
        return 1
    elif(x == 5):
        return 1
    elif(x % 2 == 0 or x < 2):
        return 0
    a = 3
    while(a * a <= x):
        if(x % a == 0):
            return 0
        a += 2
    return 1

def generate_prime(x):
    list = []
    list.append(2)
    for i in range(3,x+1,2):
        if(is_prime(i) == 1):
            list.append(i)
    return list

def count_list(x,list):
    count = 0
    for i in range(0,len(list)):
        if(list[i] > x):
            break
        elif(list[i] <= x):
            count += 1
    return count

l = []
for input in sys.stdin:
    l.append(int(input))

prime = generate_prime(max(l))
for i in range(0,len(l)):
    print count_list(l[i],prime)
### BUGGY CODE ###

s = input()

n = len(s)
ans = 0
for i in range(4, n+1):
   for j in range(0, n-i+1):
      x = int(s[j:j+i])
      if x % 2019 == 0:
         ans += 1

print(ans)


### FIXED CODE ###

s = input()[::-1] # reversed

cnt = [0] * 2019
cnt[0] = 1

num, d = 0, 1

for c in s:
   num += int(c) * d
   num %= 2019
   d *= 10
   d %= 2019
   cnt[num] += 1

ans = 0
for t in cnt:
   ans += t * (t - 1) // 2

print(ans)
### BUGGY CODE ###

k,s = map(int,input().split())

d = {}
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if(z >= 0 and z <= k):
            key = (x,y,z)
            d[key] = 1

print(len(d))


### FIXED CODE ###

k,s = map(int,input().split())

d = {}
cnt = 0
for x in range(k+1):
    for y in range(x+1):
        z = s - x - y
        if(z >= 0 and z <= y):
            if(x == y and y == z):
                cnt += 1
            elif(x == y or y == z or z == x):
                cnt += 3
            else:
                cnt += 6

print(cnt)
### BUGGY CODE ###

import bisect

n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    for i in range(c1):
      cnt+=bisect.bisect_right(arr2,mid//arr1[i])
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    for i in range(c1):
      tmp=bisect.bisect_right(arr1,mid//arr1[i])
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    for i in range(c2):
      tmp=bisect.bisect_right(arr2,mid//arr2[i])
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)

### FIXED CODE ###

#incited numpy source code from 'https://atcoder.jp/contests/abc155/submissions/10155744'

import numpy

n,k=map(int,input().split())
arr=list(map(int,input().split()))
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if ncc<k<=(ncc+zcc):
  print(0)
else:
  arr=numpy.array(arr,dtype=int)
  ms=numpy.msort(numpy.abs(arr[arr<0]))
  ps=numpy.msort(arr[arr>0])
  if k<=ncc:
    k=ncc-k
    l=0
    r=10**18+1
    while r-l!=1:
      mid=(l+r)//2
      cnt=numpy.searchsorted(ps,mid//ms,side='right')
      if cnt.sum()>k:
        r=mid
      else:
        l=mid
    print(-r)
  elif k<=(ncc+zcc):
    print(0)
  else:
    l=0
    r=10**18+1
    k-=(ncc+zcc)
    while r-l!=1:
      mid=(l+r)//2
      cnt1=numpy.searchsorted(ps,mid//ps,side='right')
      dup1=ps**2<=mid
      cnt2=numpy.searchsorted(ms,mid//ms,side='right')
      dup2=ms**2<=mid
      if (cnt1.sum()-dup1.sum()+cnt2.sum()-dup2.sum())//2>=k:
        r=mid
      else:
        l=mid
    print(r)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
b = np.array(a)
a += np.arange(n)+1
b -= np.arange(n)+1
b *= -1
c = 0
for i in a:
    c += len(b[b==i])

print(c)

### FIXED CODE ###

import numpy as np
n = int(input())
a = np.array(list(map(int,input().split())))
b = np.array(a)
a += np.arange(n)+1
b -= np.arange(n)+1
b *= -1
a = np.sort(a)
b = np.sort(b)
c = 0
for i in a:
    l = np.searchsorted(b,i,side="left")
    r = np.searchsorted(b,i,side="right")
    c += r-l

print(c)
### BUGGY CODE ###

import itertools

N, K = map(int, input().split())
A = tuple(map(int, input().split()))

MOD = 10 ** 9 + 7

dp = [[0] * (K + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
    S = [0] + list(itertools.accumulate(dp[i - 1]))
    for j in range(K + 1):
        dp[i][j] = (S[j + 1] - S[max(0, j - A[i - 1])]) % MOD
print(dp[N][K])


### FIXED CODE ###

import itertools

N, K = map(int, input().split())
A = tuple(map(int, input().split()))

MOD = 10 ** 9 + 7

dp = [[0] * (K + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
    S = [0] + list(itertools.accumulate(dp[i - 1]))
    for j in range(K + 1):
        dp[i][j] = (S[j + 1] - S[max(0, j - A[i - 1])]) % MOD
print(dp[N][K])
### BUGGY CODE ###

N = int(input())
A = sorted(map(int, input().split()))
Q = int(input())

for _ in range(Q):
  B, C = map(int, input().split())
  A = [C if a == B else a for a in A]
  print(sum(A))

### FIXED CODE ###

import collections

N = int(input())
A = sorted(map(int, input().split()))

cnt = collections.defaultdict(int)
for a in A:
    cnt[a] += 1
ans = sum(A)

Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    ans += (C - B) * cnt[B]
    cnt[C] += cnt[B]
    cnt[B] = 0
    print(ans)
### BUGGY CODE ###

def solve(pos):
    start = pos
    ans = 0
    a = 0
    b = N - 1
    for i in range(N-1):
        if a==start:
            a += 1
        elif b==start:
            b -= 1
        if abs(A[a]-A[pos])>=abs(A[b]-A[pos]):
            ans += abs(A[a]-A[pos])
            pos = a
            a += 1
        else:
            ans += abs(A[b]-A[pos])
            pos = b
            b -= 1
        #print(ans, a, b)
    #print(ans)
    return ans

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A.sort()

if N<=10000:
    pos_list = list(range(N))
else:
    M = (A[0] + A[-1])/2
    for i in range(N-1):
        if A[i]<=M and M<A[i+1]:
            break
    a = max(0, i - 500)
    b = min(N - 1, i + 500)
    pos_list = list(range(a, b+1))
    if pos_list[0]!=0:
        pos_list = [0] + pos_list
    if pos_list[-1]!= N - 1:
        pos_list.append(N-1)
#print(pos_list)

ans = 0
for pos in pos_list:
    tmp = solve(pos)
    ans = max(ans, tmp)
print(ans)


### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A.sort()

PLUS = A[int((N+1)//2):]
MINUS = A[:int((N+1)//2)]
#print(PLUS, MINUS)
ans = sum(PLUS)*2 - sum(MINUS)*2
if N%2==0:
    ans += MINUS[-1] - PLUS[0]
else:
    ans += sum(MINUS[-2:])

PLUS = A[int(N//2):]
MINUS = A[:int(N//2)]
#print(PLUS, MINUS)
ans2 = sum(PLUS)*2 - sum(MINUS)*2
if N%2==0:
    ans2 += MINUS[-1] - PLUS[0]
else:
    ans2 -= sum(PLUS[:2])

print(max(ans, ans2))
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
cnt = 0 
def search(arr,target,start,last):
#    print("target ==",target,arr[start:last+1])
    if last - start == 1:
        if(arr[last] < target):
            return last
        elif(arr[start] < target):
            return start
        else:
            return start -1
    if last < start:
        return start -1
    if start == last:
        if arr[start] < target:
            return start
        else:
            return start -1
    mid = (last - start)//2 + start
    if arr[mid] < target:
        return search(arr,target,mid + 1,last)
    else:
        return search(arr,target,start,mid)
    return start -1


for i in range(0,n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        target = a + b 
 #       print("#",a,b)
        f1 = search(l,target,j+1,n-1)
  #      print("arr[f1]",l[f1])
        cnt+= f1 - j 
  #      print("cnt: ",cnt)
print(cnt)

### FIXED CODE ###

n = int(input())
l = list(map(int,input().split(" ")))
l.sort()
cnt = 0 
import bisect
for i in range(0,n-2):
    a = l[i]
    for j in range(i+1,n-1):
        b = l[j]
        target = a + b 
  #      print("#",a,b)
        f1 = bisect.bisect_left(l,target,j+1,n)
        cnt+= f1 - 1- j
   #     print("cnt: ",cnt)
print(cnt)
### BUGGY CODE ###

from collections import defaultdict

def main():
    s = input()
    n = len(s)
    d = defaultdict(int)
    ans = 0
    num = 0
    d[0] += 1
    for i in reversed(range(n)):
        num += int(s[i]) * 10 ** (n - 1 - i)
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import defaultdict
import numpy as np
def main():
    s = input()
    n = len(s)
    d = np.zeros(2019,np.int64)
    ans = 0
    num = 0
    pow10 = 1
    d[0] = 1
    for i in reversed(range(n)):
        pow10 = pow10 * 10 % 2019
        num += int(s[i]) * pow10
        #print(num, num % 2019, i)
        mod = num % 2019
        ans += d[mod]
        d[mod] += 1
    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(1, N+1):
  for j in range(1, N+1):
   k = M - i - j
   if ( i==j or i==k or j==k): pass
   elif (i + j + k == M): ans += 1
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
ans = 0
while not (N == 0 and M == 0):
 for i in range(1, N+1):
  for j in range(i+1, N+1):
   k = M - i - j
   if ( k > N): pass
   elif  k <= j : break
   else: ans += 1
 print(ans)
 ans = 0
 N,M = map(int, input().split())
### BUGGY CODE ###

s = list(input())
MOD = 10**9 + 7
cnt = [[] for _ in range(len(s))]
i = len(s) - 1
de = 1

while i >= 0:
    if s[i] == '?':
        for j in range(10):
            cnt[i].append((j * de) % 13)
    else: cnt[i].append((int(s[i]) * de) % 13)
    i -= 1
    de *= 10

dp = [[0]*13 for _ in range(len(s))]
for i in cnt[0]:
    dp[0][i] = 1
for i in range(1, len(s)):
    for j in cnt[i]:
        for k in range(13):
            if dp[i-1][k] != 0:
                dp[i][(j + k)%13] += dp[i - 1][k]
                dp[i][(j + k)%13] %= MOD
print(dp[-1][5])


### FIXED CODE ###

s = list(input())
MOD = 10**9 + 7
cnt = [[] for _ in range(len(s))]
i = len(s) - 1
de = 1

while i >= 0:
    if s[i] == '?':
        for j in range(10):
            cnt[i].append((j * de) % 13)
    else: cnt[i].append((int(s[i]) * de) % 13)
    i -= 1
    de *= 10
    de %= 13

dp = [[0]*13 for _ in range(len(s))]
for i in cnt[0]:
    dp[0][i] = 1
for i in range(1, len(s)):
    for j in cnt[i]:
        for k in range(13):
            if dp[i-1][k] != 0:
                dp[i][(j + k)%13] += dp[i - 1][k]
                dp[i][(j + k)%13] %= MOD
print(dp[-1][5])
### BUGGY CODE ###

a,b,x=map(int,input().split())
A=set(range(a,a+x))|set(range(b-x+1,b+1))
r=set(range(a,b+1))
print(*sorted(A&r),sep='\n')

### FIXED CODE ###

a,b,x=map(int,input().split())
A=sorted(set(range(a,min(a+x,b+1)))|set(range(max(b-x+1,a),b+1)))
print(*A,sep='\n')
### BUGGY CODE ###

# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=deque(s)
gyaku_fig=False
for ll in l:
    if ll[0]=='1':
        t_str=list(t_str)
        t_str=t_str[::-1]
        t_str=deque(t_str)
    elif ll[0]=='2':
            if ll[1]=='1':
                t_str.appendleft(ll[2])
                # t_str=list(ll[2])+t_str
            elif ll[1]=='2':
                t_str.append(ll[2])
                # t_str+=list(ll[2])

t_str=list(t_str)
ans=''.join(t_str)
print(ans)

# t_str=s
# gyaku_fig=False
# for ll in l:
#     if ll[0]=='1':
#         if gyaku_fig==False:
#             gyaku_fig=True
#         elif gyaku_fig==True:
#             gyaku_fig=False
#     elif ll[0]=='2':
#         if gyaku_fig==True:
#             if ll[1]=='1':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='2':
#                 t_str+=ll[2]
#         elif gyaku_fig==False:
#             if ll[1]=='2':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='1':
#                 t_str+=ll[2]        
# if gyaku_fig==True:
#     print(t_str)
# else:
#     print(t_str[::-1])


### FIXED CODE ###

# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

if cnt%2==0:
    ans=''.join(ans)
else:
    ans=ans[::-1]
    ans=''.join(ans)
print(ans)
### BUGGY CODE ###

from decimal import Decimal
import sys
input = sys.stdin.readline


def dist(x1, x2, y1, y2):
    return (y1-y2)*(y1-y2)+(x1-x2)*(x1-x2)


def farthest(x, y):
    ret = 0
    point = (-1, -1)
    for u, v in X:
        d = dist(x, u, y, v)
        if d > ret:
            ret = d
            point = u, v
    return ret, point


N = int(input())
X = []
for _ in [0]*N:
    x, y = map(int, input().split())
    X.append((x, y))

x = (max(x for x, y in X) - min(x for x, y in X))/2
y = (max(y for x, y in X) - min(y for x, y in X))/2
x = Decimal(str(x))
y = Decimal(str(y))
step = Decimal('0.5')
o = 1
eps = Decimal('0.000000000000000001')
while o > eps:
    _, (u, v) = farthest(x, y)
    x += (u-x)*step
    y += (v-y)*step
    step *= Decimal('0.999')
    o = (abs(u-x)+abs(x-y))*step

ans, _ = farthest(x, y)
ans **= Decimal('0.5')
print(ans)

### FIXED CODE ###

from decimal import Decimal
import sys
input = sys.stdin.readline


def dist(x1, x2, y1, y2):
    return (y1-y2)*(y1-y2)+(x1-x2)*(x1-x2)


def farthest(x, y):
    ret = 0
    point = (-1, -1)
    for u, v in X:
        d = dist(x, u, y, v)
        if d > ret:
            ret = d
            point = u, v
    return ret, point


N = int(input())
X = []
for _ in [0]*N:
    x, y = map(int, input().split())
    X.append((x, y))

x = (max(x for x, y in X) - min(x for x, y in X))/2
y = (max(y for x, y in X) - min(y for x, y in X))/2
x = Decimal(str(x))
y = Decimal(str(y))
step = Decimal('0.5')
o = 1
eps = Decimal('0.00000000000001')
while o > eps:
    _, (u, v) = farthest(x, y)
    x += (u-x)*step
    y += (v-y)*step
    step *= Decimal('0.999')
    o = (abs(u-x)+abs(x-y))*step

ans, _ = farthest(x, y)
ans **= Decimal('0.5')
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N_ken,M_si = map(int,input().split())
ken_year_map = {}
ken_year_list = []

for si in range(1,M_si+1):
    ken,year = map(int,input().split())
    ken_year_list.append([ken,year])
    if ken in ken_year_map:
        ken_year_map[ken].append(year)
    else:
        ken_year_map[ken] = [year]
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in ken_year_list:
    print((str(ken*1000000 + ken_year_map[ken].index(year)+1)).zfill(12))


### FIXED CODE ###

import sys
input = sys.stdin.readline
import bisect

N_ken,M_si = map(int,input().split())
ken_year_map = {}
for i in range(1,N_ken+1):ken_year_map[i]=[]

ken_list = [0]*M_si
year_list = [0]*M_si

for si in range(M_si):
    ken_list[si],year_list[si] = map(int,input().split())
    ken_year_map[ken_list[si]] += [year_list[si]]
        
for i in ken_year_map:
    ken_year_map[i].sort()

for ken,year in zip(ken_list,year_list):
    print('{:06}{:06}'.format(ken,bisect.bisect_right(ken_year_map[ken], year)))