#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<set>
#include<cstring>
#include <algorithm>
#define N 52
#define inf 0x7f7f7f7f
using namespace std;
int p[N],pp[N];
int ma[N][N],ans[N][N];
//void print2(int m[][N],int n)
//{
// for(int i=0; i<52; i++)
// {
// cout<<"i="<<i+1<<" ";
// for(int j=0; j<52; j++)
// cout<<m[i][j]<<" ";
// cout<<endl;
// }
//}
void multi(int a[][N],int b[][N],int c[][N])//有规律,1和0
{
memset(c,0,sizeof(ma));
// cout<<"sizeof(ma)="<<sizeof(ma)<<endl;////////////////
for(int i=0; i<52; i++)
{
int h=0;
for(; h<52; h++)
if(a[i][h])
break;
int j=0;
for(; j<52; j++)
if(b[h][j])
break;
c[i][j]=1;
}
}
void dfs(int k,int ma[][N],int ans[][N])
{
if(k==1)
{
memcpy(ans,ma,sizeof(ma)*N*N);//N*N?????????????
return ;
}
if(k&1)
{
int m[N][N],mm[N][N];
dfs(k/2,ma,m);
multi(m,m,mm);
multi(ma,mm,ans);
}
else
{
int m[N][N];
dfs(k/2,ma,m);
multi(m,m,ans);
}
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("ex.in","r",stdin);
//#endif
int T,ncase=0,l,r,n;
scanf("%d",&T);
while(T--)
{
for(int i=0; i<52; i++)
scanf("%d",&p[i]);
scanf("%d%d%d",&n,&l,&r);
l--;
r--;
memset(ma,0,sizeof(ma));
int i=0,j;
for(j=l; j<=r; i++,j++)
{
ma[j][i]=1;
}
for(j=0; j<l; j++,i++)
{
ma[j][i]=1;
}
for(j=r+1; j<52; j++,i++)
{
ma[j][i]=1;
}
dfs(n,ma,ans);
for(int i=0; i<52; i++)
{
for(int k=0; k<52; k++)
{
if(ans[k][i])
{
pp[i]=p[k];
}
}
}
printf("Case #%d:",++ncase);
for(int i=0; i<52; i++)
printf(" %d",pp[i]);
printf("\n");
}
return 0;
}
其实该题可以看周期(有规律)!!