#include <iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
// your code goes here
int n,r;
scanf("%d %d", &n, &r);
int loc;
scanf("%d", &loc);
int xy[loc+1][2],i,j;
for(i=0;i<loc; i++){
scanf("%d %d" , &xy[i][0], &xy[i][1]);
}
int s;
scanf("%d", &s);
int xys[s+1][3];
for(i=0;i<s;i++){
scanf("%d %d %d", &xys[i][0], &xys[i][1], &xys[i][2]);
}
// precomputing distances
vector<int> vec[loc+1];
for(i=0; i < loc; i++){
for(j=0; j <s; j++){
float distx = abs(xys[j][0] - xy[i][0]);
float disty = abs(xys[j][1] - xy[i][1]);
float d = (distx*distx) + (disty*disty);
d = sqrt(d);
if( d <= r){
vec[i].push_back(j);
}
}
}
// consider all possible locations
long int tot = 1<<loc;
long int ans = 0;
bool visit[s+1];
// least number with n set bits
i = 1<<n;
i -= 1;
while(i < tot){
int calc = 0;
for(j=0;j<s; j++)
visit[j] = 0;
for(j = 0; j < loc; j++ ){
if( (i&(1<<j)) ){
// we are considering j'th location
for(int k = 0; k< vec[j].size(); k++ ){
if( visit[vec[j][k]] == 0){
calc += xys[vec[j][k]][2];
visit[vec[j][k]] = 1;
}
}
}
}
// cout<<"Total : "<<calc<<endl;
if( ans < calc )
ans = calc;
// find the next higher number with same number of set bits
int right = i&(-i);
int next = i+right;
int op = (i^next);
op = op/right;
op>>=2;
i = next|op;
}
printf("%d\n",ans);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTx2ZWN0b3I+CiNpbmNsdWRlPGNtYXRoPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkvLyB5b3VyIGNvZGUgZ29lcyBoZXJlCglpbnQgbixyOwoJCglzY2FuZigiJWQgJWQiLCAmbiwgJnIpOwoJCglpbnQgbG9jOwoJc2NhbmYoIiVkIiwgJmxvYyk7CgoJaW50IHh5W2xvYysxXVsyXSxpLGo7CgkKCWZvcihpPTA7aTxsb2M7IGkrKyl7Cgk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