#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <map>
#include <set>
#include <cstdio>
#include <cassert>
using namespace std;

typedef complex<double> P;

const double eps = 1e-6;
bool equals(double a, double b) { return abs(a-b) < eps; }
bool equals(P a, P b) { return equals(a.real(),b.real()) && equals(a.imag(),b.imag()); }

namespace std {
  bool operator < (const P& a, const P& b) {
    if(!equals(a.real(),b.real())) return a.real() < b.real();
    if(!equals(a.imag(),b.imag())) return a.imag() < b.imag();
    return false;
  }
}


struct L : public vector<P> {
  L() : vector<P>(2) {}
  L(P a, P b) {
    push_back(a);
    push_back(b);
  }
};

struct Road : public L {
  double w;
  Road() : L() {}
  Road(P a, P b, double w) : L(a,b), w(w) {}
};

double dot(P a, P b) { return a.real()*b.real()+a.imag()*b.imag(); }
double norm(P a) { return dot(a,a); }
double abs(P a) { return sqrt(norm(a)); }
double cross(P a, P b) { return a.real()*b.imag()-a.imag()*b.real(); }

int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a,b) > eps) return 1;
  if(cross(a,b) < -eps) return -1;
  if(dot(a,b) < -eps) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

bool isParallel(P a, P b) { return equals(cross(a,b),0.0); }

bool isIntersect(P a1, P a2, P b1, P b2) {
  return ( ccw(a1,a2,b1)*ccw(a1,a2,b2) <= 0 &&
	   ccw(b1,b2,a1)*ccw(b1,b2,a2) <= 0 );
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b,b1-a1)/cross(b,a);
}


struct Edge { int to, cap, rev; };

const int MAX_N = 51;
const int INF = 1<<24;

vector<Road> road;
set<P> C;
P D;
vector<vector<Edge> > E;
map<P,int> id;

int V;
bool* vis;

void add_edge(int a, int b, int w) {
  E[a].push_back((Edge){b,w,E[b].size()});
  E[b].push_back((Edge){a,0,(int)E[a].size()-1});
  E[a].push_back((Edge){b,0,E[b].size()});
  E[b].push_back((Edge){a,w,(int)E[a].size()-1});
}


int dfs(int v, int t, int f) {
  if(v == t) return f;
  vis[v] = true;
  for(int i = 0; i < E[v].size(); ++i) {
    Edge &e = E[v][i];
    if(!vis[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
	e.cap -= d;
	E[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(true) {
    fill(vis, vis+V, false);
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int solve() {
  vector<P> crossP;
  for(int i = 0; i < road.size(); ++i) {
    crossP.push_back(road[i][0]);
    crossP.push_back(road[i][1]);
    for(int j = i+1; j < road.size(); ++j) {
      if(isIntersect(road[i][0],road[i][1],road[j][0],road[j][1]) &&
	 !isParallel(road[i][1]-road[i][0],road[j][1]-road[j][0])) {
	crossP.push_back(getCrossP(road[i][0],road[i][1],road[j][0],road[j][1]));
      }
    }
  }

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

  vector<Road> uroad;
  for(int j = 0; j < road.size(); ++j) {
    vector<Road> troad;
    troad.push_back(road[j]);
    for(int i = 0; i < crossP.size(); ++i) {
      for(int k = 0; k < troad.size(); ++k) {
	if(!equals(crossP[i],troad[k][0]) && !equals(crossP[i],troad[k][1]) &&
	   ccw(troad[k][0],troad[k][1],crossP[i]) == 0) {
	  double w = troad[k].w;
	  double nw = w*abs(crossP[i]-troad[k][0])/abs(troad[k][1]-troad[k][0]);
	  troad.push_back(Road(crossP[i],troad[k][1],w-nw));
	  troad[k].w = nw;
	  troad[k][1] = crossP[i];
	  break;
	}
      }
    }
    for(int k = 0; k < troad.size(); ++k) uroad.push_back(troad[k]);
  }

  for(int i = 0; i < uroad.size(); ++i) {
    for(int j = i+1; j < uroad.size(); ++j) {
      if((equals(uroad[i][0],uroad[j][0]) && equals(uroad[i][1],uroad[j][1])) ||
	 (equals(uroad[i][0],uroad[j][1]) && equals(uroad[i][1],uroad[j][0]))) {
	uroad[i].w += uroad[j].w;
	uroad[j].w = 0.0;
      }
    }
  }

  {
    vector<Road> tmp;
    for(int i = 0; i < uroad.size(); ++i)
      if(uroad[i].w >= 1.0)
	tmp.push_back(uroad[i]);
    uroad = tmp;
  }

  E.push_back(vector<Edge>());
  for(int i = 0; i < uroad.size(); ++i) {
    if(uroad[i].w == 0.0) continue;
    if(id[uroad[i][0]] == 0) {
      int tmp = id.size();
      id[uroad[i][0]] = tmp;
      E.push_back(vector<Edge>());
    }
    if(id[uroad[i][1]] == 0) {
      int tmp = id.size();
      id[uroad[i][1]] = tmp;
      E.push_back(vector<Edge>());
    }
    add_edge(id[uroad[i][0]],id[uroad[i][1]],(int)uroad[i].w);
    if(C.find(uroad[i][0]) != C.end()) add_edge(0,id[uroad[i][0]],100.0);
    if(C.find(uroad[i][1]) != C.end()) add_edge(0,id[uroad[i][1]],100.0);
  }
  V = id.size()+1;
  vis = new bool[V];
  return id[D] == 0 ? 0 : max_flow(0,id[D]);
}

int main() {
  int n, m;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    P a, b;
    int w;
    cin >> a.real() >> a.imag() >> b.real() >> b.imag() >> w;
    road.push_back(Road(a,b,w));
  }
  cin >> m;
  for(int i = 0; i < m; ++i) {
    P p;
    cin >> p.real() >> p.imag();
    C.insert(p);
  }
  cin >> D.real() >> D.imag();
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 0