#include <cstdio>
#include <vector>
#include <math.h>
#define loop(i,a,b) for(int i=a;i<b;++i)
using namespace std;
static const int MAX = 51;
struct pt
{
	int x, y, z;
};
struct possib
{
	int fly_cost, fuel_cost, fuel_rest;
};
int sqr( int n )
{
	return n*n;
}
int fuel( pt A, pt B )
{
	double len = sqrt (double( sqr(A.x-B.x) + sqr(A.y-B.y) + sqr(A.z-B.z) ) );
	int res = len/100;
	if ( len/100 - res > 0 )
		++res;
	return res;
}
vector <possib> poss[MAX];
pt A,pl[MAX];
int n,b,k,neww=0,total_lowest_fuel_cost = 1000,rest
	,fuel_cost[MAX] // Стоимость топлива на планете
	,lowest_fuel_cost[MAX]
;
int main()
{
	freopen("space.in","rt",stdin);
	freopen("space.out","wt",stdout);
	scanf("%d%d%d%d%d%d",&A.x,&A.y,&A.z,&n,&b,&k);
	b--;
	rest=n;
	loop(i,0,n)
	{
		scanf("%d%d%d%d",&pl[i].x,&pl[i].y,&pl[i].z,&fuel_cost[i]);
		lowest_fuel_cost[i] = fuel_cost[i];
		if ( fuel_cost[i] < total_lowest_fuel_cost )
			total_lowest_fuel_cost = fuel_cost[i];
	}
	loop(i,0,n)
	{
		int fuel_rest = k - fuel( A, pl[i] );
		if ( fuel_rest >= 0 )
		{
			possib p;
			p.fuel_rest = fuel_rest;
			p.fly_cost = 0;
			p.fuel_cost = fuel_cost[i]; 
			poss[i].push_back( p );
			++neww;
		}
	}

	if ( neww == 0 )
	{
		printf("-1");
		return 0;
	}

	loop(i,0,n)
		if ( lowest_fuel_cost[i] == total_lowest_fuel_cost )
		{
			--rest;
		}

	while ( rest )
	{
		loop(i,0,n)
		{
			// if ( i != b )
			{
				loop(j,0,n)
					if ( i != j )
					{
						loop(k,0,poss[i].size()) // for all possibilities
						{
							possib p;
							int fuel_need = fuel( pl[i], pl[j] );
							fuel_need -= poss[i][k].fuel_rest;
							p.fuel_rest=0;
							if ( fuel_need < 0 )
							{
								p.fuel_rest = - fuel_need;
								fuel_need = 0;
							}
							p.fuel_cost = poss[i][k].fuel_cost; // new fuel cost
							if ( fuel_cost[j] < p.fuel_cost )
								p.fuel_cost = fuel_cost[j];

							if ( p.fuel_cost == total_lowest_fuel_cost && lowest_fuel_cost[j] != total_lowest_fuel_cost )
							{
								lowest_fuel_cost[j] = total_lowest_fuel_cost;
								--rest;
							}

							int add_cost = fuel_need * poss[i][k].fuel_cost;
							p.fly_cost = poss[i][k].fly_cost + add_cost;
							poss[j].push_back( p );
						}
					}
			}
		}
	}

	int ans = poss[b][0].fly_cost;
	loop(i,1,poss[b].size())
		if ( poss[b][i].fly_cost < ans )
			ans = poss[b][i].fly_cost;

	printf("%d",ans);

	return 0;
}