#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using psi=pair<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD ((ll)1e9+7)
void get(){}template<class H,class...T>void get(H&h,T&...t){cin>>h;get(t...);}
template<class T>void geti(T&a){for(auto&_:a)cin>>_;}
template<class T>void getii(T&a){for(auto&_:a)geti(_);}
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
#define dcl(...) double __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)
template<class F,class S>void add(map<F,S>&mp,F f,S s){if(mp.find(f)==mp.end())mp[f]=F();mp[f]+=s;}

double hypot3(double a, double b, double c){
    return a*a+b*b+c*c;
}

 
vs sepstr(string s,string r){vs res;regex R("[^|]+");for(auto _:r)s=regex_replace(s,regex("[\\"+string{_}+"]"),"|"+string{_}+"|");for(sregex_iterator itr(all(s),R),end;itr!=end;++itr)res.pb(itr->str());return res;}

template<class T>string bitstr(T x){return typeid(T)==typeid(int)?bitset<32>(x).to_string('_','#'):bitset<64>(x).to_string();}
template<class T>int bitcnt(T x){return typeid(T)==typeid(int)?__builtin_popcount(x):__builtin_popcountll(x);}
template<class T>int bitdig(T x){return x?typeid(T)==typeid(int)?32-__builtin_clz(x):64-__builtin_clzll(x):0;}
template<class T>int bitpow(T x){return x?typeid(T)==typeid(int)?__builtin_ctz(x):__builtin_ctzll(x):0;}


int main(){
    while(1){
        dclt(int,n,m);
        dcl(r);
        if(r==0) break;
        using vvd=vector<vector<double>>;
        vvd bal;
        rep(i,n){
            dcl(x,y,z,s);
            bal.pb({x,y,z,s});
        }
        vvd lig;
        rep(i,m){
            dcl(x,y,z,s);
            lig.pb({x,y,z,s});
        }
        dcl(x,y,z);
        for(auto &b:bal){
            b[0]-=x;
            b[1]-=y;
            b[2]-=z;
        }
        for(auto &l:lig){
            l[0]-=x;
            l[1]-=y;
            l[2]-=z;
            l[3]/=hypot3(l[0],l[1],l[2]);
        }

        vector<bitset<2000>> st(m,bitset<2000>(0));
        rep(i,m){
            rep(j,n){
                auto b=bal[j];
                double d[2];
                d[0]=sqrt(hypot3(lig[i][0]-b[0],lig[i][1]-b[1],lig[i][2]-b[2]));
                d[1]=sqrt(hypot3(b[0],b[1],b[2]));
                double p=d[1]/(d[0]+d[1]);
                double pos[3];
                pos[0]=lig[i][0]*p;
                pos[1]=lig[i][1]*p;
                pos[2]=lig[i][2]*p;
                double dist=sqrt(hypot3(lig[i][0],lig[i][1],lig[i][2]));
                double suisen=sqrt(hypot3(pos[0]-b[0],pos[1]-b[1],pos[2]-b[2]));
                if((d[0]<b[3] && d[1]>b[3]) || (d[0]>b[3] && d[1]<b[3]) || (d[0]>b[3] && d[1]>b[3] &&suisen<b[3])){
                    st[i].set(j,1);
                }
            }
        }
        double ans=-1.0;
        rep(i,1<<m){
            bitset<2000> sum(0);
            double val=0;
            int p=i;
            while(p){
                val+=lig[__builtin_ffs(p)-1][3];
                sum|=st[__builtin_ffs(p)-1];
                p&=(p-1);
            }
            if(sum.count()<=r){
                ans=max(ans,val);
            }
        }
        cout<<fixed<<setprecision(16)<<ans<<endl;
    }
	return 0;
}



Measured memory_bytes: 3492