import java.util.Scanner;

public class Main {
  public static int head, tail;
  private final static int MAX = 100000;
  private static char[] Queue = new char[MAX];

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
  }

  private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  }

  private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  }

} import java.util.Scanner; Scanner java.util public class Main {
  public static int head, tail;
  private final static int MAX = 100000;
  private static char[] Queue = new char[MAX];

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
  }

  private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  }

  private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  }

} Main public static int head head tail; tail private final static int MAX = 100000; MAX 100000 private static char[] Queue = new char[MAX]; Queue new char[MAX] MAX public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  } main {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    } true {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    } char[] S = sc.next().toCharArray(); S sc.next().toCharArray() sc.next().toCharArray sc.next() sc.next sc initialize() initialize for (char s : S)
        enqueue(s); char s S enqueue(s); enqueue(s) enqueue s if (Character.toString(S[0]).equals("-"))
        break; Character.toString(S[0]).equals("-") Character.toString(S[0]).equals Character.toString(S[0]) Character.toString Character S[0] S 0 "-" break; int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      } {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      } int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        } int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
          enqueue(dequeue());
        } {
          enqueue(dequeue());
        } enqueue(dequeue()) enqueue dequeue() dequeue for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      } int i = head; int i = head; i head i < tail i tail i++ i++ i {
        System.out.print(Queue[i]);
      } {
        System.out.print(Queue[i]);
      } System.out.print(Queue[i]) System.out.print System.out System System.out Queue[i] Queue i System.out.println() System.out.println System.out System System.out String[] args args private static void initialize() {
    head = tail = 0;
  } initialize {
    head = tail = 0;
  } head = tail = 0 head tail = 0 tail 0 private static boolean isEmpty() {
    return head == tail;
  } isEmpty {
    return head == tail;
  } return head == tail; head == tail head tail private static boolean isFull() {
    return head == (tail + 1) % MAX;
  } isFull {
    return head == (tail + 1) % MAX;
  } return head == (tail + 1) % MAX; head == (tail + 1) % MAX head (tail + 1) % MAX (tail + 1) tail 1 MAX private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  } enqueue {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  } if (isFull()) {
      throw new Error("Queue Over Flow");
    } isFull() isFull {
      throw new Error("Queue Over Flow");
    } throw new Error("Queue Over Flow"); new Error("Queue Over Flow") Queue[tail] = x Queue[tail] Queue tail x tail = (tail + 1) % MAX tail (tail + 1) % MAX (tail + 1) tail 1 MAX char x x private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  } dequeue {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  } if (isEmpty()) {
      throw new Error("Queue Under Flow");
    } isEmpty() isEmpty {
      throw new Error("Queue Under Flow");
    } throw new Error("Queue Under Flow"); new Error("Queue Under Flow") char x = Queue[head]; x Queue[head] Queue head head = (head + 1) % MAX head (head + 1) % MAX (head + 1) head 1 MAX return x; x public class Main {
  public static int head, tail;
  private final static int MAX = 100000;
  private static char[] Queue = new char[MAX];

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
  }

  private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  }

  private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  }

} public class Main {
  public static int head, tail;
  private final static int MAX = 100000;
  private static char[] Queue = new char[MAX];

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
  }

  private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  }

  private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  }

} Main
import java.util.Scanner;

public class Main {
  public static int head, tail;
  private final static int MAX = 100000;
  private static char[] Queue = new char[MAX];

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    while (true) {
      char[] S = sc.next().toCharArray();
      initialize();
      for (char s : S)
        enqueue(s);
      if (Character.toString(S[0]).equals("-"))
        break;
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        int m = sc.nextInt();
        for (int j = 0; j < m; j++) {
          enqueue(dequeue());
        }
      }
      for (int i = head; i < tail; i++) {
        System.out.print(Queue[i]);
      }
      System.out.println();
    }
  }

  private static void initialize() {
    head = tail = 0;
  }

  private static boolean isEmpty() {
    return head == tail;
  }

  private static boolean isFull() {
    return head == (tail + 1) % MAX;
  }

  private static void enqueue(char x) {
    if (isFull()) {
      throw new Error("Queue Over Flow");
    }
    Queue[tail] = x;
    tail = (tail + 1) % MAX;
  }

  private static char dequeue() {
    if (isEmpty()) {
      throw new Error("Queue Under Flow");
    }
    char x = Queue[head];
    head = (head + 1) % MAX;
    return x;
  }

}
