#define init {1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,1000000001,}
N,M,L,Q;
D[300][300]={
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
init,
};
i,j,k;
a,b,c;
main()
{
	scanf("%d%d%d",&N,&M,&L);
	for(i=0;i<M;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		--a;
		--b;
		D[a][b]=D[b][a]=c;
	}
	for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=0;i<N;i++)for(j=0;j<N;j++)
	{
		D[i][j]=D[i][j]>L?1000000000:1;
	}
	for(k=0;k<N;k++)for(i=0;i<N;i++)for(j=0;j<N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	scanf("%d",&Q);
	for(i=0;i<Q;i++)
	{
		scanf("%d%d",&a,&b);
		--a;
		--b;
		printf("%d\n",D[a][b]<1000000000?D[a][b]-1:-1);
	}
}

Measured memory_bytes: 768