using System;
using System.Collections.Generic;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
using System.IO;
using System.Text;

//============================================================================
namespace Sweet
{
    class Program
    {
        static StreamWriter writer = null;
        //============================================================================
        static void setstdio(string[] args)
        {
            if (0 < args.Length)
            {
                // Redirect standard input from the console to the input file.
                Console.SetIn(new StreamReader(args[0]));
                if (args.Length == 2)
                {
                    // Attempt to open output file.
                    writer = new StreamWriter(args[1]);
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);
                }
            }
        }
        //============================================================================
        static void rotatestr(string[] str, int n)
        {
            string bfr; int i=0;

            foreach (string a in str)
            {
                bfr = a.Substring(n) + a.Substring(0, n);
                str[i++] = bfr;
            }
        }
        //============================================================================
        static int Swing()
        {
            int i,cnt,pronum;
            string words;// = new List<string>();
            string str; //var chars cary;// = new char[201] ;

            for (i =pronum= 0, words=""; ; i++)
            {
                str = Console.ReadLine();
                if (str.Substring(0, 1) == "-")
                    break;
                //var chars = str.ToCharArray;
                if (0<str.CompareTo("9"))
                {
                    words=str;
                    str = Console.ReadLine();
                    for (cnt=pronum = 0; cnt < int.Parse(str); cnt++)
                        pronum += int.Parse(Console.ReadLine());
                    cnt = pronum % words.Length;
                    str = words.Substring(cnt) + words.Substring(0, cnt);
                    Console.WriteLine(str);
                }
            }
            return 0;
        }

        //============================================================================
        private static bool isalpha(char v)
        {
            if ('a' <= v && v <= 'z' || 'A' <= v && v <= 'Z')
                return true;
            return false;
        }

        //============================================================================
        static void Main(string[] args)
        {
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            setstdio(args);

            while(Swing()!=0);
            //sw.Stop();
            //Console.WriteLine("duration = {0}", sw.Elapsed);
            if (writer != null)
                writer.Close();
            //Console.ReadLine();
        }
        //============================================================================
    }
}

Measured memory_bytes: 9916