import java.awt.geom.Point2D;
import java.awt.geom.Line2D;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class ANARC_2010_H_alt
{
	BufferedReader in;
	Scanner inr;
	PrintWriter out;

	void initIO() throws IOException
	{
		inr = new Scanner(System.in);
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new OutputStreamWriter(System.out));
	}

	int n, k;

	int[] a, c;
	
	int cycleLen[];
	
	String s;

	void swap(int[] a, int[] c, int k1, int k2)
	{
		int ta = a[k1]; a[k1] = a[k2]; a[k2] = ta;
		int tc = c[k1]; c[k1] = c[k2]; c[k2] = tc;
	}
	
	void step(int[] a, int[] c, int k, int n)
	{
		int min = Integer.MAX_VALUE;
		int imin = -1;
		for (int i = 0; i < n; i++)
			if (c[i] < min)
			{
				min = c[i];
				imin = i;
			}
		int p = imin;
		c[p]++;
		for (int cc = 0; cc < k % n; cc++)
		{
			if (p == n - 1)
			{
				for (int i = n - 1; i > 0; i--)
					swap(a, c, i, i - 1);
				p = 0;
			}
			else
			{
				swap(a, c, p, p + 1);
				p++;
			}
		}
	}
	
	void print(int[] a, int[] c, int k)
	{
		for (int i = 0; i < n; i++)
			System.out.print(s.charAt(a[i]));
		System.out.print("    ");
		for (int i = 0; i < n; i++)
			System.out.print(c[i]);
		System.out.println(" " + k);
	}
	
	int get_cycle_len(int n)
	{
		int[] a = new int[n], c = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = i;
		for (int i = 0; ; i++)
		{
			step(a, c, i + 1, n);
			boolean f = true;
			for (int j = 0; j < n; j++)
			{
				if (a[j] != j || c[j] != c[0])
					f = false;
			}
			if (f)
				return i + 1;
		}
	}
	
	void solve() throws Exception
	{
		// precalc
		cycleLen = new int[27];
		for (int i = 1; i <= 26; i++)
			cycleLen[i] = get_cycle_len(i);
		
		int nt = 0;
		while (true)
		{
			k = nextInt();
			if (k == 0)
				break;
			s = nextString();
			n = s.length();
			a = new int[n];
			c = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = i;
			k %= cycleLen[n];
			for (int i = 0; i < k; i++)
				step(a, c, i + 1, n);
			StringBuilder res = new StringBuilder();
			for (int i = 0; i < n; i++)
				res.append(s.charAt(a[i]));
			out.println("" + (++nt) + ". " + res.toString());
			out.flush();
		}
	}

	void run() throws Exception
	{
		initIO();
		solve();
		out.flush();
	}

	int nextInt()
	{
		return inr.nextInt();
	}

	String nextLine()
	{
		return inr.nextLine();
	}

	String nextString()
	{
		return inr.next();
	}

	public static void main(String[] args) throws Exception
	{
		new ANARC_2010_H_alt().run();
	}
}
