#include <iostream>
#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
float dist[loc+1][s+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);
dist[i][j] = d;
}
}
// consider all possible locations
long int tot = 1<<loc;
long int ans = 0;
bool visit[s+1];
// lest number with n set bits
i = 1<<n;
i -= 1;
while(i < tot){
int calc = 0;
// check which locations are considered in i
for(int l =0; l < s; l++)
visit[l] = 0;
for(j = 0; j < loc; j++ ){
if( (i&(1<<j)) ){
// we are considering j'th location
for(int k = 0; k < s; k++){
float d = dist[j][k];
if( d <= r && visit[k] == 0){
calc += xys[k][2];
visit[k] = 1;
// cout<<k<<" ";
}
}
}
}
// 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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZTxjbWF0aD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJaW50IG4scjsKCQoJc2NhbmYoIiVkICVkIiwgJm4sICZyKTsKCQoJaW50IGxvYzsKCXNjYW5mKCIlZCIsICZsb2MpOwoKCWludCB4eVtsb2MrMV1bMl0saSxqOwoJCglmb3IoaT0wO2k8bG9jOyBpKyspewoJCXNjYW5mKCIlZCAlZCIgLCAmeHlbaV1bMF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