
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		StringBuilder card = new StringBuilder();
		StringBuilder answer = new StringBuilder();
		Scanner scan = new Scanner(System.in);
		//n????????¢?????????????????????????????????????????????StringBuilder?????\??????
		card.append(scan.nextLine());
		//?????£?????????????????°
		int shuffle = Integer.parseInt(scan.nextLine());
		//?????£????????????????????°
		String h = scan.nextLine();
		int i = 0;
		int w = 0;
		String hoge = "";
		
		while(true) {
			while(i < shuffle) {
				card.append( card.substring(0, Integer.parseInt(h)) );
				card.delete(0, Integer.parseInt(h));
				if(h.equals("-") || i == (shuffle - 1)){
					//?????£????????????????????£???????????????answer???????´?
					answer.append(card.toString() + "\n");
					break;
				}else{
					h = scan.nextLine();
				}
				i++;
			}
			//?¬???????????????????????????????while??????????????????
			hoge = scan.nextLine();
			if( i == (shuffle - 1) && hoge.equals("-")){
				break;
			}else{
				i = 0;
				card.delete(0, card.length());
				card.append(hoge);
				shuffle = Integer.parseInt(scan.nextLine());
				h = scan.nextLine();
			}
		}
		System.out.print(answer.toString());
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz