#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int INF=1<<29;
const double EPS=1e-6;

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

bool operator<(const point<double> &a,const point<double> &b){
	return a.x+EPS<b.x || abs(a.x-b.x)<EPS && a.y+EPS<b.y;
}

bool operator==(const point<double> &a,const point<double> &b){
	return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;
}

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

enum {CCW=1,CW=-1,ON=0};
int ccw(const point<double> &a,const point<double> &b,const point<double> &c){
	double rdir=cross(b-a,c-a);
	if(rdir> EPS) return CCW;
	if(rdir<-EPS) return CW;
	return ON;
}

template<class T>
struct line{ point<T> a,b; };

template<class T>
struct segment{
	point<T> a,b;
	int w; // 重み
	operator line<T>()const{ return (line<T>){a,b}; }
};

template<class T>
bool intersect(const segment<T> &S1,const segment<T> &S2){
	if(max(S1.a.x,S1.b.x)<min(S2.a.x,S2.b.x)
	|| max(S1.a.y,S1.b.y)<min(S2.a.y,S2.b.y)
	|| max(S2.a.x,S2.b.x)<min(S1.a.x,S1.b.x)
	|| max(S2.a.y,S2.b.y)<min(S1.a.y,S1.b.y)) return false;
	return ccw(S1.a,S1.b,S2.a)*ccw(S1.a,S1.b,S2.b)<=0
		&& ccw(S2.a,S2.b,S1.a)*ccw(S2.a,S2.b,S1.b)<=0;
}

point<double> get_intersect(const line<double> &L1,const line<double> &L2){
	double a1=cross(L1.b-L1.a,L2.b-L2.a);
	double a2=cross(L1.b-L1.a,L1.b-L2.a);
	if(abs(a1)<EPS) return L1.a;
	return L2.a+a2/a1*(L2.b-L2.a);
}

template<class T>
double dist(const point<T> &a,const point<T> &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool cover(const segment<double> &S,const point<double> &p){
	return dist(S.a,p)+dist(p,S.b)<dist(S.a,S.b)+EPS;
}

const int V_MAX=3000;

template<class T>
struct edge{
	int v,rev;
	T capa,flow;
};

template<class T>
void add_undirected_edge(vector< edge<T> > *G,int u,int v,T capa){
	G[u].push_back((edge<T>){v,G[v].size()  ,capa,0});
	G[v].push_back((edge<T>){u,G[u].size()-1,capa,0});
}

template<class T>
T augment(int n,vector< edge<T> > *G,int s,int t){
	static int pre[V_MAX];
	static bool vis[V_MAX];
	rep(u,n) vis[u]=(u==s);

	queue< pair<int,T> > Q;
	Q.push(make_pair(s,0));
	rep(i,G[s].size()){
		edge<T> &e=G[s][i];
		Q.front().second=max(Q.front().second,e.capa-e.flow);
	}

	T res=0;
	while(!Q.empty()){
		int u=Q.front().first;
		T water=Q.front().second; Q.pop();

		if(u==t){ res=water; break; }

		rep(i,G[u].size()){
			edge<T> &e=G[u][i];
			if(!vis[e.v] && e.capa-e.flow>0){
				vis[e.v]=true;
				pre[e.v]=e.rev;
				Q.push(make_pair(e.v,min(water,e.capa-e.flow)));
			}
		}
	}

	if(res>0){
		for(int v=t;v!=s;){
			edge<T> &e1=G[v][pre[v]];
			edge<T> &e2=G[e1.v][e1.rev];
			e1.flow-=res;
			e2.flow+=res;
			v=e1.v;
		}
	}

	return res;
}

template<class T>
T Edmonds_Karp(int n,vector< edge<T> > *G,int s,int t){
	T ans=0;
	for(T water=1;water>0;ans+=water) water=augment(n,G,s,t);
	return ans;
}

int main(){
	int n; scanf("%d",&n);
	segment<double> S[50];
	rep(i,n) scanf("%lf%lf%lf%lf%d",&S[i].a.x,&S[i].a.y,&S[i].b.x,&S[i].b.y,&S[i].w);

	vector< point<double> > P;
	rep(i,n){
		P.push_back(S[i].a);
		P.push_back(S[i].b);
		rep(j,i) if(intersect(S[i],S[j])) P.push_back(get_intersect(S[i],S[j]));
	}

	sort(P.begin(),P.end());
	P.erase(unique(P.begin(),P.end()),P.end());

	static double cap[V_MAX][V_MAX]; // 辺の容量
	rep(i,n){
		vector< pair<point<double>,int> > Q; // S[i] の上に乗っている P の点全体
		rep(u,P.size()) if(cover(S[i],P[u])) Q.push_back(make_pair(P[u],u));
		sort(Q.begin(),Q.end());
		rep(j,(int)Q.size()-1){
			int u=Q[j].second,v=Q[j+1].second;
			cap[u][v]+=S[i].w*dist(Q[j].first,Q[j+1].first)/dist(S[i].a,S[i].b);
			cap[v][u]+=S[i].w*dist(Q[j].first,Q[j+1].first)/dist(S[i].a,S[i].b);
		}
	}

	vector< edge<int> > G[V_MAX];
	rep(u,P.size()) rep(v,u)  if(cap[u][v]>0) {
		add_undirected_edge(G,u,v,(int)(cap[u][v]+EPS));
	}

	int src=P.size(),snk;
	int m; scanf("%d",&m);
	rep(i,m+1){
		point<double> p; scanf("%lf%lf",&p.x,&p.y);
		int u=find(P.begin(),P.end(),p)-P.begin();
		if(i<m) add_undirected_edge(G,src,u,INF);
		else    snk=u;
	}

	printf("%d\n",Edmonds_Karp(P.size()+1,G,src,snk));

	return 0;
}

Measured memory_bytes: 0