using System;
using System.Linq;

class C
{
	static void Main()
	{
		long[] Ts = readLongArray();
		long   T  = Ts[0];

		for(long C=1; C<=T; ++C)
		{
			long[] RkN = readLongArray();
			long   R = RkN[0];
			long   k = RkN[1];
			long   N = RkN[2];
			long[] g = readLongArray();

			Console.WriteLine("Case #{0}: {1}", C, solveSmall(R,k,N,g));
		}
	}

	static long[] readLongArray()
	{
		return (from s in Console.ReadLine().Split(' ') select long.Parse(s)).ToArray();
	}

	static long solveSmall(long R, long k, long N, long[] g)
	{
		long totalEarn = 0;

		for(int i=0; i<R; ++i)
		{
			long ride = 0;
			for(int q=0; q<g.Length; ++q)
				if( ride + g[q] > k )
				{
					g = rotate(g, q);
					break;
				}
				else
				{
					ride += g[q];
				}
			totalEarn += ride;
		}

		return totalEarn;
	}

	static long[] rotate(long[] g, int s)
	{
		long[] g2 = new long[g.Length];
		for(int i=s; i<g.Length; ++i)
			g2[i-s] = g[i];
		for(int i=0; i<s; ++i)
			g2[i+g.Length-s] = g[i];
		return g2;
	}
}
