#include<bits/stdc++.h>
#define mo 1000000009
using namespace std;
int left[50123];
int right[50123];
int a[50123];
int b[50123];
int q[50123];
int n,m,D;
int main(){
	int T,cas;
	scanf("%d",&T);
	for(cas=1;cas<=T;cas++){
		printf("Case #%d: ",cas);
		scanf("%d%d%d",&n,&m,&D);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<=n;i++)
			scanf("%d",&b[i]);
		memset(left,0,sizeof(left));
		memset(right,0,sizeof(right));
		int head=0,tail=0,ind=0,pt=1;
		q[1]=a[1];
		head=1,tail=1;
		while(ind<m){
			ind++;
			while(tail>=head && b[ind]>=a[ q[head] ] + D) head++;
			while(pt<n && b[ind]+D>a[pt+1]){
				pt++;
				q[++tail]=a[pt];
			}
			left[ind]=q[head]-1;
			if(pt!=1)
				right[ind]=q[tail];
			else
				right[ind]=
		}
		
	}
}
