Title: Shuffle

Your task is to shuffle a deck of n cards, each marked by an alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top. The deck is represented by a string where the first character corresponds to the bottom card and the last character to the top card.

For example, a shuffle with h = 4 to the deck "abcdeefab" moves "abcd" to the end of "eefab", resulting in "eefababcd".

Write a program that reads a deck (a string) and a sequence of h, and prints the final state (a string).

Input:
The input consists of multiple datasets. Each dataset is given as:
- A string representing a deck
- The number of shuffles m
- h1, h2, ..., hm
The input ends with a single character '-' for the string.

Constraints:
- The length of the string ≤ 200
- 1 ≤ m ≤ 100
- 1 ≤ hi < The length of the string
- The number of datasets ≤ 10

Output:
For each dataset, print a string representing the final state in a line.

Sample Input:
aabc
3
1
2
1
vwxyz
2
3
4
-

Sample Output:
aabc
xyzvw

# Buggy version:
while True:

    string = str(input())
    box = ""
    
    
    if string == "-":
        break
    
    shuffle = int(input())

    h = [0]*shuffle

    for a in range(shuffle):
        h[a] = int(input())

    for b in range(shuffle):
        box = string[0:h[b]]
        string = string[h[b]:]
        string = string+box
        box = ""
        print(string)

    print(string)


# Fixed version:
while True:

    string = str(input())
    box = ""
    
    
    if string == "-":
        break
    
    shuffle = int(input())

    h = [0]*shuffle

    for a in range(shuffle):
        h[a] = int(input())

    for b in range(shuffle):
        box = string[0:h[b]]
        string = string[h[b]:]
        string = string+box
        box = ""

    print(string)

# Buggy version:
while True:
  cards = str(input())
  if cards == '-':
    break
  
  n = int(input())
  for i in range(n):
    p = str(input())
    cards = cards[p:] + cards[:p]
  print(cards)


# Fixed version:
while True:
  cards = str(input())
  if cards == '-':
    break
  
  n = int(input())
  for i in range(n):
    p = int(input())
    cards = cards[p:] + cards[:p]
  print(cards)

# Buggy version:
while True:
    text = input()
    if text == '-':
        break

    count = int(input())
    for c in range(count):
        index = int(input())
        text - text[index:] + text[:index]

print(text)

# Fixed version:
while True:
    text = input()
    if text == '-':
        break

    count = int(input())
    for c in range(count):
        index = int(input())
        text = text[index:] + text[:index]

    print(text)

# Buggy version:
s = []
n = []
while True:
    hoge = input()
    if hoge == '-':
        break

    for i in range(int(input())):
        h = int(input())
        hoge.replace(hoge,hoge[h:] + hoge[:h])
    s += [hoge]
for i in s: print(i)

# Fixed version:
s = []
while True:
    hoge = input()
    if hoge == '-':
        break
    num = int(input())
    for i in range(num):
        h = int(input())
        hoge = hoge.replace(hoge,hoge[h:] + hoge[:h])
    s += [hoge]
for i in s: print(i)

# Buggy version:
while(1):
  
 sen1=input()
  
 if sen1=="-":
   break
 
 suff=int(input())
  
 for i in range(suff):
    h=int(input())
    sen2=sen1[h:]+sen1[:h]

 print(sen2)

# Fixed version:
while(1):
  
 sen1=input()
  
 if sen1=="-":
   break
 
 suff=int(input())
  
 for i in range(suff):
    h=int(input())
    sen1=sen1[h:]+sen1[:h]

 print(sen1)

# Buggy version:
import sys

def shuffle( cards ):
	h = int( sys.stdin.readline() )
	s = cards[ 0 : h ]
	cards = cards.lstrip( s )
	cards += s
	return cards

while True:
	cards = sys.stdin.readline().rstrip()
	if '-' == cards:
		break
	m = int( sys.stdin.readline() )
	for i in range( 0, m ):
		cards = shuffle( cards )
	print( cards )

# Fixed version:
import sys

def shuffle( cards ):
    h = int( sys.stdin.readline() )
    cards = cards[ h : ] + cards[ 0 : h ]
    return cards

while True:
    cards = sys.stdin.readline().rstrip()
    if '-' == cards:
        break
    m = int( sys.stdin.readline())
    for i in range( m ):
        cards = shuffle( cards )
    print( cards )

# Buggy version:
while True:
    if input() == "-":
        break
    else:
        s = 0
        string = input()
        for i in range(int(input())):
            s += int(input())

        s = s % len(string)
        print(string[s:len(string)] + string[0:s])

# Fixed version:
while True:
    string = input()
    if string == "-":
        break
    else:
        s = 0
        for i in range(int(input())):
            s += int(input())

        s = s % len(string)
    print(string[s:] + string[:s])

# Buggy version:
import sys
dataset = sys.stdin.readlines()

seq = 0

while dataset[seq] != '-\n':
 s = dataset[seq]
 len = len(s) - 1
 s = s[:len]
 seq += 1
 n = int(dataset[seq][0])
 seq += 1
 for i in range(seq, seq + n):
  h = int(dataset[i][0])
  s = s[h:] + s[0:h]
 print(s)
 seq += n
 

# Fixed version:
import sys
dataset = sys.stdin.readlines()

seq = 0

while dataset[seq] != '-\n':
 s = dataset[seq]
 l = len(s) - 1
 s = s[:l]
 seq += 1
 n = dataset[seq]
 l = len(n) - 1
 n = int(n[:l])
 seq += 1
 for i in range(seq, seq + n):
  h = dataset[i]
  l = len(h) - 1
  h = int(h[:l])
  s = s[h:] + s[0:h]
 print(s)
 seq += n

# Buggy version:
Str=[]
H=[]
h=[]
while True:
    x=input()
    if x=='-':
        break
    Str.append(x)
    m=int(input())
    for i in range(m):
        x=int(input())
        h.append(x)
    H.append(h)
    h=[]
print(Str)
print(H)
for i in range(len(Str)):
    a=Str[i]
    for j in range(len(H[i])):
        a=''.join([a[H[i][j]:],a[:H[i][j]]])
    Str[i]=a
for str in Str:
    print(str)

# Fixed version:
Str=[]
H=[]
h=[]
while True:
    x=input()
    if x=='-':
        break
    Str.append(x)
    m=int(input())
    for i in range(m):
        x=int(input())
        h.append(x)
    H.append(h)
    h=[]
for i in range(len(Str)):
    a=Str[i]
    for j in range(len(H[i])):
        a=''.join([a[H[i][j]:],a[:H[i][j]]])
    Str[i]=a
for str in Str:
    print(str)

# Buggy version:
while True:
    C = input()
    if C == "-":
        break
    count = int(input())
    shuffle = [int(input() for i in range(count))]
    for h in shuffle:
        C = C[h:] + C[:h]
    print(C)

# Fixed version:
while True:
    C = input()
    if C == "-":
        break
    count = int(input())
    shuffle = [int(input()) for i in range(count)]
    for h in shuffle:
        C = C[h:] + C[:h]
    print(C)

# Buggy version:
import re
array = []
lines = []
count = 0
while True:
    n = input()
    if n == "-":
        break
    array.append(n)
for i in range(len(array)):
    if re.compile("[a-z]").search(array[i]):
        if count > 0:
            lines.append(stt)
        count += 1
        stt = array[i]
    else:
        stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])]
        if i == len(array)-1:
            lines.append(stt)
for i in range(len(lines)):
    print(lines[i])

# Fixed version:
import re
array = []
lines = []
count = 0
while True:
    n = input()
    if n == "-":
        break
    array.append(n)
for i in range(len(array)):
    if re.compile("[a-z]").search(array[i]):
        fuck = i+1
        if count > 0:
            lines.append(stt)
        count += 1
        stt = array[i]
    else:
        if i == fuck:
            continue
        stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])]
        if i == len(array)-1:
            lines.append(stt)
for i in range(len(lines)):
    print(lines[i])

# Buggy version:
while 1:
    n=input()
    if n=='-':
        break
    m=[i for i in range(len(n))]
    count=int(input())
    for i in range(count):
        l=int(input())
        for j in range(len(n)):
            m[j]=n[(l+j)%len(n)]
        n=m
    for i in range(len(n)):
        print(n[i],end="")
    print()        

# Fixed version:
while 1:
    n=input()
    if n=='-':
        break
    m=[i for i in range(len(n))]
    count=int(input())
    for i in range(count):
        l=int(input())
        for j in range(len(n)):
            m[j]=n[(l+j)%len(n)]
        n=m.copy()
    for i in range(len(n)):
        print(n[i],end="")
    print()

# Buggy version:
al=input()
m=int(input())
for i in range(m):
  n = int(input())
  if n=='-':
    break
  else:
   al= al[n:] + al[:n]
print(al)

# Fixed version:
while True:
 al=input()
 if al=='-':
     break
 else:
  m=int(input())
  for i in range(m):
   n = int(input())
   al= al[n:] + al[:n]
  print(al)

# Buggy version:
while True:
    s = input()
    if s == '-':
        break

    n = int(input())
    for mi in range(m):
        h = int(input())

        s = s[:h] + s[h:]

    print(s)

# Fixed version:
while True:
    s=input()
    if s == '-':
        break
 
 
    m=int(input())
    for mi in range(m):
        h = int(input())
        s = s[h:] + s[:h]
 
    print(s)

# Buggy version:
while True:
    string = list(input())
    if len(string) == 1 and string[0] == "-":
        break
    num = int(input())
    for i in range(num):
        times = int(input())
        tmp = string[:times]
        del string[:times]
        string += tmp
    print(" ".join(string))

# Fixed version:
while True:
    string = list(input())
    if len(string) == 1 and string[0] == "-":
        break
    num = int(input())
    for i in range(num):
        times = int(input())
        tmp = string[:times]
        del string[:times]
        string += tmp
    print("".join(string))

# Buggy version:
while True:
    a=input()
    if a=='-':
        break
     else:
        n=int(input())
        for i in range(n):
             h=int(input())
             a=a[h:]+a[:h]
    print(a)

# Fixed version:
while True:
    a=input()
    if a=='-':
        break
    else:
        n=int(input())
        for i in range(n):
             h=int(input())
             a=a[h:]+a[:h]
    print(a)

# Buggy version:
str = input()
while not str == '-':
  n = int(input())
  for i in range(n):
    str = str[n:] + [:n-1]
  print(str)
  str = input() 

# Fixed version:
str = input()
while not str == '-':
  n = int(input())
  for i in range(n):
    h = int(input())
    str = str[h:] + str[:h]
  print(str)
  str = input()

# Buggy version:
def main():
    while True:
        S = input()
        if S == "-":
            break

        n_shuffle = int(input())
        hs = [int(input()) for _ in range(n_shuffle)]

        for h in hs:
            S = S[-h:] + S[:-h]

        print(S)

if __name__ == "__main__":
    main()

# Fixed version:
def main():
    while True:
        S = input()
        if S == "-":
            break

        n_shuffle = int(input())
        hs = [int(input()) for _ in range(n_shuffle)]

        for h in hs:
            S = S[h:] + S[:h]

        print(S)

if __name__ == "__main__":
    main()

# Buggy version:
l = []
while 1:
  s = input()
  if s == "-": break
  for _ in range(int(input())):
    h = int(input())
    s = s[h:] + s[:h]
  l += [s]
  print(l)
for e in l: print(e)


# Fixed version:
while 1:
  s = input()
  if s == "-": break
  for _ in range(int(input())):
    h = int(input())
    s = s[h:] + s[:h]
  print(s)

# Buggy version:
# AOJ ITP1_9_B

def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    while True:
        string = input()
        if string == "-": break
        n = int(input())  # シャッフル回数
        for i in range(n):
            h = int(input())
            front = string[0 : h]  # 0番からh-1番まで
            back = string[h : len(string)]  # h番からlen-1番まで
            string = back + front
            print(string)
        print(string)

if __name__ == "__main__":
    main()



# Fixed version:
# AOJ ITP1_9_B

def main():
    while True:
        string = input()
        if string == "-": break
        n = int(input())  # シャッフル回数
        for i in range(n):
            h = int(input())
            front = string[0 : h]  # 0番からh-1番まで
            back = string[h : len(string)]  # h番からlen-1番まで
            string = back + front
        print(string)

if __name__ == "__main__":
    main()

# Buggy version:

while True:
    s = input()
    if s == "-":break
    loop_cnt = int(input())
    for i in range(loop_cnt):
        h = int(input())
        s = s[h:] + s[:h]
    else:
        print(s)
print(s)

# Fixed version:
while True:
    s = input()
    if s == "-":
        break
    else:
        N = int(input())
        for i in range(N):
            h = int(input())
            s = s[h:] + s[:h]
    print(s)

# Buggy version:
while True:
	s = input()
	if s == "-":
		break
	m = int(input())
	for n in range(m):
		h = int(input())
		s = s[0:h] + s[h:]
	print(s)

# Fixed version:
while True:
    s = input()
    if s == '-':
        break
    m = int(input())
    for i in range(m):
        h = int(input())
        s = s[h:] + s[0:h]
    print(s)

# Buggy version:
while True:
    s = input()
    if s == '-':
        break
    m = int(input())
    for mi in range(m):
        h = int(input())

        s = s[:h] + s[h:]
    print(s)

# Fixed version:
while True:
    s=input()
    if s=="-":
        break
    m=int(input())
    for _ in range(m):
        h=int(input())
        s=s[h:]+s[:h]
    print(s)

# Buggy version:
while True:
    card = input()
    if card == '-': break
    for i in range(int(input())):
        a = int(input())
        card = card[:a] + card[a:]
    print(card)



# Fixed version:
while True:
  card=input()
  if card =='-':
    break
  for i in range(int(input())):
      a = int(input())
      card = card[a:] + card[:a]
  print(card)

# Buggy version:
A = input()
while(A != '-'):
	m = int(input)
	for i in range(m):
		h = int(input())
		A = A[h:]+A[:h]
	print(A)
	A = input()


# Fixed version:
desk = input()
while desk != '-':
    m = int(input())
    for i in range(m):
        h = int(input())
        desk = desk[h:] + desk[:h]
    print(desk)
    desk = input()

# Buggy version:
while True:
    _=input()
    if _ == '-':
        break
    for i in range(int(input())):
        l=int(input())
        _=_[l:]+[:l]
    print(_)    


# Fixed version:
while True:
    word = input()
    if word == '-':
        break

    for _ in range(int(input())):
        i = int(input())
        word = word[i:] + word[:i]
    print(word)

# Buggy version:
while 1:
    s = input()
    if s == '-':break
    n = input()
    for i in range(n):
        h = int(input())
        s = s[h:] + s[:h]
    print(s)

# Fixed version:
while 1:
    s=input()
    if s=='-':break
    n=int(input())
    for i in range(n):
        t=int(input())
        s=s[t:]+s[:t]
    print(s)

# Buggy version:
while True:
    cards = input()
    if cards == "-":
        break
    m = int(input())
    for i in range(m):
        h = int(input())
        cards = cards[h:] + cards[:h]
        print(cards)

# Fixed version:
while True:
    deck = input()
    if deck == "-":
        break
    m = int(input())
    for i in range(m):
        h = int(input())
        deck = deck[h:] + deck[:h]
    print(deck)

# Buggy version:
while True:
    s = input()
    if s == '-': break
    n = int(input())
    for i in range(n):
        h = int(input())
        s = s[-h:] + s[:-h]
    print(s)

# Fixed version:
while True:
  s = input()
  if s=="-":
    break
  m = int(input())
  for i in range(m):
    h = int(input())
    s = s[h:]+s[:h]
  print(s)