
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());
	}
} import java.util.Scanner; Scanner java.util 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());
	}
} 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());
	} main {
		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());
	} StringBuilder card = new StringBuilder(); card new StringBuilder() StringBuilder answer = new StringBuilder(); answer new StringBuilder() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) card.append(scan.nextLine()) card.append card scan.nextLine() scan.nextLine scan int shuffle = Integer.parseInt(scan.nextLine()); shuffle Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan String h = scan.nextLine(); h scan.nextLine() scan.nextLine scan int i = 0; i 0 int w = 0; w 0 String hoge = ""; 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();
			}
		} 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();
			}
		} 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++;
			} i < shuffle 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++;
			} card.append( card.substring(0, Integer.parseInt(h)) ) card.append card card.substring(0, Integer.parseInt(h)) card.substring card 0 Integer.parseInt(h) Integer.parseInt Integer h card.delete(0, Integer.parseInt(h)) card.delete card 0 Integer.parseInt(h) Integer.parseInt Integer h if(h.equals("-") || i == (shuffle - 1)){
					//?????£????????????????????£???????????????answer???????´?
					answer.append(card.toString() + "\n");
					break;
				}else{
					h = scan.nextLine();
				} h.equals("-") || i == (shuffle - 1) h.equals("-") h.equals h "-" i == (shuffle - 1) i (shuffle - 1) shuffle 1 {
					//?????£????????????????????£???????????????answer???????´?
					answer.append(card.toString() + "\n");
					break;
				} answer.append(card.toString() + "\n") answer.append answer card.toString() + "\n" card.toString() card.toString card "\n" break; {
					h = scan.nextLine();
				} h = scan.nextLine() h scan.nextLine() scan.nextLine scan i++ i hoge = scan.nextLine() hoge scan.nextLine() scan.nextLine scan 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();
			} i == (shuffle - 1) && hoge.equals("-") i == (shuffle - 1) i (shuffle - 1) shuffle 1 hoge.equals("-") hoge.equals hoge "-" {
				break;
			} break; {
				i = 0;
				card.delete(0, card.length());
				card.append(hoge);
				shuffle = Integer.parseInt(scan.nextLine());
				h = scan.nextLine();
			} i = 0 i 0 card.delete(0, card.length()) card.delete card 0 card.length() card.length card card.append(hoge) card.append card hoge shuffle = Integer.parseInt(scan.nextLine()) shuffle Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan h = scan.nextLine() h scan.nextLine() scan.nextLine scan System.out.print(answer.toString()) System.out.print System.out System System.out answer.toString() answer.toString answer String[] args args 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());
	}
} 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());
	}
} Main

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());
	}
}