// Arup Guha
// 9/22/2013
// Solution to 2010 ACPC Problem H: Jumping Beans

import java.util.*;

public class h {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int loop = 1;

		// Go through each case.
		while (n != 0) {

			String s = stdin.next();

			// Calculate one cycle of operations, abstracted away to a permutation matrix.
			int[] f = getF(getIdentity(s.length()), s.length());

			// Calculate how many times we repeat this cycle.
			int exp = n/s.length();

			// And how many steps we have to perform at the end.
			int leftover = n%s.length();

			// Assign our start point, based on full cycles.
			int[] g;
			if (exp > 0)
				g = fastExpo(f, exp);
			else
				g = getIdentity(f.length);

			// Compute the ending function.
			int[] h = getF(g, leftover);

			// Map to a string and print.
			String ans = getString(s, h);
			System.out.println(loop+". "+ans);
			n = stdin.nextInt();
			loop++;
		}
	}

	// Returns the identity function.
	public static int[] getIdentity(int n) {
		int[] array = new int[n];
		for (int i=0; i<n; i++)
			array[i] = i;
		return array;
	}

	// Returns the result f(s).
	public static String getString(String s, int[] f) {
		char[] ans = new char[s.length()];
		for (int i=0; i<s.length(); i++)
			ans[i] = s.charAt(f[i]);
		return new String(ans);
	}

	// Returns the function composition g of f.
	public static int[] mult(int[] f, int[] g) {
		int n = f.length;
		int[] ans = new int[n];

		// Quite literally, compute g of f.
		for (int i=0; i<n; i++)
			ans[i] = g[f[i]];
		return ans;
	}

	// Returns f composed with itself exp times.
	public static int[] fastExpo(int[] f, int exp) {

		// Identity.
		if (exp == 0)
			return getIdentity(f.length);

		// The function itself.
		else if (exp == 1)
			return f;

		// Fast expo step.
		else if (exp%2 == 0) {
			int[] tmp = fastExpo(f, exp/2);
			return mult(tmp, tmp);
		}

		// Regular decomposition.
		else
			return mult(f, fastExpo(f, exp-1));
	}

	// Pre-condition: len <= s.length()
	public static int[] getF(int[] f, int len) {

		int n = f.length;
		boolean[] used = new boolean[n];

		// Loop until the number of characters.
		for (int j=1; j<=len; j++) {

			// Find our start point.
			int start = 0;
			while (used[f[start]]) start++;
			used[f[start]] = true;

			// Must swap j times.
			for (int k=0; k<j; k++) {
				swap(f, start);
				start = (start+1)%n;
			}
		}
		return f;
	}

	// Performs one swap of array on index i, as specified in the problem.
	public static void swap(int[] array, int i) {

		// Annoying end case.
		if (i == array.length-1) {
			int temp = array[array.length-1];
			for (int j=array.length-1; j>0; j--)
				array[j] = array[j-1];
			array[0] = temp;
		}
		else {
			int temp = array[i];
			array[i] = array[i+1];
			array[i+1] = temp;
		}
	}
}