#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<iomanip>
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
#define FOR(i,b,c) for(int i = b ; i < c ; i++ )
#define x first
#define y second
#define eps 1e-9
#define MAXD 2
#define eps 1e-9
#define pi acos(-1.0)
using namespace std ;
struct Vec {
int d;
double val[MAXD];
Vec() {
d=2;
}
Vec( double a , double b ) {
val[0] = a ;
val[1] = b ;
d = 2 ;
}
Vec add ( Vec b ) {
Vec res;
FOR(i,0,d) res.val[i] = val[i] + b.val[i];
return res;
}
Vec sub ( Vec b ) {
Vec res;
FOR(i,0,d) res.val[i] = val[i] - b.val[i];
return res;
}
Vec mul ( double t ) {
Vec res;
FOR(i,0,d)res.val[i] = val[i] * t;
return res;
}
Vec div ( double t ) {
Vec res;
FOR(i,0,d) res.val[i] = val[i] / t;
return res;
}
Vec perp2D() {
Vec res = (*this);
swap ( res.val[0], res.val[1] );
res.val[0] *= -1;
return res;
}
double dot ( Vec v ) {
double res = 0;
d = 2 ;
for ( int i = 0; i < d; i++ ) res += val[i] * v.val[i];
return res;
}
double length () {
return sqrt ( this->dot( *this ) );
}
Vec unitVec () {
return (*this).div ( length() );
}
double angleBetween ( Vec b ) {
double res = dot( b ) / ( length() * b.length() );
if ( res > 1 ) res = 1;
if ( res < -1 ) res = -1;
return acos (res);
}
double polarAngle2D() {
double res = atan2 ( val[1], val[0] );
if ( res + eps < 0 ) res += 2 * pi;
return res;
}
double cross2D ( Vec v ) {
return val[0]*v.val[1] - val[1]*v.val[0];
}
};
struct Line {
Vec a, b;
Line() {}
Line( Vec x, Vec y ) {
a = x;
b = y.sub ( x );
}
double length() {
return b.length();
}
Vec atPos ( double t ) {
return a.add ( b.mul ( t ) );
}
bool overlapParallel ( Line l ) {
double p, q, r, s;
if ( b.val[0] == 0 ) {
p = a.val[1];
q = atPos(1).val[1];
r = l.a.val[1];
s = l.atPos ( 1 ).val[1];
if ( min ( r, s ) > max ( p, q ) ) return false;
if ( max ( r, s ) < min ( p, q ) ) return false;
return true;
} else {
p = a.val[0];
q = atPos(1).val[0];
r = l.a.val[0];
s = l.atPos ( 1 ).val[0];
if ( min ( r, s ) > max ( p, q ) ) return false;
if ( max ( r, s ) < min ( p, q ) ) return false;
return true;
}
}
char LineAndLineIntersection2D ( Line l, double &t, double &s ) {
if ( b.cross2D ( l.b) == 0 ) {
if ( l.a.sub(a).cross2D(l.b) == 0 ) {
if ( overlapParallel ( l ) ) return 'o';
else return 'p';
} else return 'd';
}
Vec w = a.sub ( l.a );
Vec p = l.b.perp2D(), z = b.perp2D();
t = -(w.dot(p))/p.dot(b);
s = w.dot(z)/z.dot(l.b);
return 'i';
}
};
vector< Vec > V ;
int main() {
#ifdef kryptonyte
freopen("in.txt","r",stdin ) ;
#endif
int n ;
scanf("%d",&n) ;
vector<Vec> V ;
for( int i = 0 ; i < n ; i++ ) {
double x , y ;
scanf("%lf%lf",&x,&y) ;
Vec tmp = Vec(x,y);
V.push_back( tmp ) ;
}
int query ;
scanf("%d",&query ) ;
int ans = 0 ;
bool f = 0 ;
while( query-- ) {
int n1,n2,n3,n4 ;
scanf("%d%d%d%d",&n1,&n2,&n3,&n4) ;
if( !f ) {
n1-- ,n2--,n3--,n4-- ;
Line L1 = Line( V[n1] , V[n2] ) ;
Line L2 = Line( V[n3] , V[n4] ) ;
double t , s ;
L1.LineAndLineIntersection2D(L2,t,s) ;
Vec pt = L1.atPos(t) ;
if( fabs(pt.val[0]-0) < eps && fabs(pt.val[1]-0) < eps ) {
f = 1 ;
}
ans ++ ;
V.push_back(pt) ;
}
}
if( f )cout << ans << "\n" ;
else cout << 0 << "\n" ;
return 0 ;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8dmVjdG9yPgojaW5jbHVkZTxpb21hbmlwPgoKI2RlZmluZSByZXAoaSxuKSBmb3IoIGludCBpID0gMCA7IGkgPCBuIDsgaSsrICkKI2RlZmluZSBGT1IoaSxiLGMpIGZvcihpbnQgaSA9IGIgOyBpIDwgYyA7IGkrKyApCiNkZWZpbmUgeCBmaXJzdAojZGVmaW5lIHkgc2Vjb25kCiNkZWZpbmUgZXBzIDFlLTkKI2RlZmluZSBNQVhEIDIKI2RlZmluZSBlcHMgMWUtOQojZGVmaW5lIHBpIGFjb3MoLTEuMCkKdXNpbmcgbmFtZXNwYWNlIHN0ZCA7CnN0cnVjdCBWZWMgewogICAgaW50IGQ7CiAgICBkb3VibGUgdmFsW01BWERdOwogICAgVmVjKCkgewogICAgICAgIGQ9MjsKICAgIH0KICAgIFZlYyggZG91YmxlIGEgLCBkb3VibGUgYiApIHsKICAgICAgICB2YWxbMF0gPSBhIDsKICAgICAgICB2YWxbMV0gPSBiIDsKICAgICAgICBkID0gMiA7CiAgICB9CiAgICBWZWMgYWRkICggVmVjIGIgKSB7CiAgICAgICAgVmVjIHJlczsKICAgICAgICBGT1IoaSwwLGQpIHJlcy52YWxbaV0gPSB2YWxbaV0gKyBiLnZhbFtpXTsKICAgICAgICByZXR1cm4gcmVzOwogICAgfQogICAgVmVjIHN1YiAoIFZlYyBiICkgewogICAgICAgIFZlYyByZXM7CiAgICAgICAgRk9SKGksMCxkKSByZXMudmFsW2ldID0gdmFsW2ldIC0gYi52YWxbaV07CiAgICAgICAgcmV0dXJuIHJlczsKICAgIH0KICAgIFZlYyBtdWwgKCBkb3VibGUgdCApIHsKICAgICAgICBWZWMgcmVzOwogICAgICAgIEZPUihpLDAsZClyZXMudmFsW2ldID0gdmFsW2ldICogdDsKICAgICAgICByZXR1cm4gcmVzOwogICAgfQogICAgVmVjIGRpdiAoIGRvdWJsZSB0ICkgewogICAgICAgIFZlYyByZXM7CiAgICAgICAgRk9SKGksMCxkKSByZXMudmFsW2ldID0gdmFsW2ldIC8gdDsKICAgICAgICByZXR1cm4gcmVzOwogICAgfQogICAgVmVjIHBlcnAyRCgpIHsKICAgICAgICBWZWMgcmVzID0gKCp0aGlzKTsKICAgICAgICBzd2FwICggcmVzLnZhbFswXSwgcmVzLnZhbFsxXSApOwogICAgICAgIHJlcy52YWxbMF0gKj0gLTE7CiAgICAgICAgcmV0dXJuIHJlczsKICAgIH0KICAgIGRvdWJsZSBkb3QgKCBWZWMgdiApIHsKICAgICAgICBkb3VibGUgcmVzID0gMDsKICAgICAgICBkID0gMiA7CiAgICAgICAgZm9yICggaW50IGkgPSAwOyBpIDwgZDsgaSsrICkgcmVzICs9IHZhbFtpXSAqIHYudmFsW2ldOwogICAgICAgIHJldHVybiByZXM7CiAgICB9CiAgICBkb3VibGUgbGVuZ3RoICgpIHsKICAgICAgICByZXR1cm4gc3FydCAoIHRoaXMtPmRvdCggKnRoaXMgKSApOwogICAgfQogICAgVmVjIHVuaXRWZWMgKCkgewogICAgICAgIHJldHVybiAoKnRoaXMpLmRpdiAoIGxlbmd0aCgpICk7CiAgICB9CiAgICBkb3VibGUgYW5nbGVCZXR3ZWVuICggVmVjIGIgKSB7CiAgICAgICAgZG91YmxlIHJlcyA9IGRvdCggYiApIC8gKCBsZW5ndGgoKSAqIGIubGVuZ3RoKCkgKTsKICAgICAgICBpZiAoIHJlcyA+IDEgKSByZXMgPSAxOwogICAgICAgIGlmICggcmVzIDwgLTEgKSByZXMgPSAtMTsKICAgICAgICByZXR1cm4gYWNvcyAocmVzKTsKICAgIH0KICAgIGRvdWJsZSBwb2xhckFuZ2xlMkQoKSB7CiAgICAgICAgZG91YmxlIHJlcyA9IGF0YW4yICggdmFsWzFdLCB2YWxbMF0gKTsKICAgICAgICBpZiAoIHJlcyArIGVwcyA8IDAgKSByZXMgKz0gMiAqIHBpOwogICAgICAgIHJldHVybiByZXM7CiAgICB9CgogICAgZG91YmxlIGNyb3NzMkQgKCBWZWMgdiApIHsKICAgICAgICByZXR1cm4gdmFsWzBdKnYudmFsWzFdIC0gdmFsWzFdKnYudmFsWzBdOwogICAgfQp9OwoKc3RydWN0IExpbmUgewogICAgVmVjIGEsIGI7CiAgICBMaW5lKCkge30KICAgIExpbmUoIFZlYyB4LCBWZWMgeSApIHsKICAgICAgICBhID0geDsKICAgICAgICBiID0geS5zdWIgKCB4ICk7CiAgICB9CiAgICBkb3VibGUgbGVuZ3RoKCkgewogICAgICAgIHJldHVybiBiLmxlbmd0aCgpOwogICAgfQogICAgVmVjIGF0UG9zICggZG91YmxlIHQgKSB7CiAgICAgICAgcmV0dXJuIGEuYWRkICggYi5tdWwgKCB0ICkgKTsKICAgIH0KICAgIGJvb2wgb3ZlcmxhcFBhcmFsbGVsICggTGluZSBsICkgewogICAgICAgIGRvdWJsZSBwLCBxLCByLCBzOwogICAgICAgIGlmICggYi52YWxbMF0gPT0gMCApIHsKICAgICAgICAgICAgcCA9IGEudmFsWzFdOwogICAgICAgICAgICBxID0gYXRQb3MoMSkudmFsWzFdOwogICAgICAgICAgICByID0gbC5hLnZhbFsxXTsKICAgICAgICAgICAgcyA9IGwuYXRQb3MgKCAxICkudmFsWzFdOwogICAgICAgICAgICBpZiAoIG1pbiAoIHIsIHMgKSA+IG1heCAoIHAsIHEgKSApIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgaWYgKCBtYXggKCByLCBzICkgPCBtaW4gKCBwLCBxICkgKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHAgPSBhLnZhbFswXTsKICAgICAgICAgICAgcSA9IGF0UG9zKDEpLnZhbFswXTsKICAgICAgICAgICAgciA9IGwuYS52YWxbMF07CiAgICAgICAgICAgIHMgPSBsLmF0UG9zICggMSApLnZhbFswXTsKICAgICAgICAgICAgaWYgKCBtaW4gKCByLCBzICkgPiBtYXggKCBwLCBxICkgKSByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIGlmICggbWF4ICggciwgcyApIDwgbWluICggcCwgcSApICkgcmV0dXJuIGZhbHNlOwogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICB9CiAgICBjaGFyIExpbmVBbmRMaW5lSW50ZXJzZWN0aW9uMkQgKCBMaW5lIGwsIGRvdWJsZSAmdCwgZG91YmxlICZzICkgewogICAgICAgIGlmICggYi5jcm9zczJEICggbC5iKSA9PSAwICkgewogICAgICAgICAgICBpZiAoIGwuYS5zdWIoYSkuY3Jvc3MyRChsLmIpID09IDAgKSB7CiAgICAgICAgICAgICAgICBpZiAoIG92ZXJsYXBQYXJhbGxlbCAoIGwgKSApIHJldHVybiAnbyc7CiAgICAgICAgICAgICAgICBlbHNlIHJldHVybiAncCc7CiAgICAgICAgICAgIH0gZWxzZSByZXR1cm4gJ2QnOwogICAgICAgIH0KICAgICAgICBWZWMgdyA9IGEuc3ViICggbC5hICk7CiAgICAgICAgVmVjIHAgPSBsLmIucGVycDJEKCksIHogPSBiLnBlcnAyRCgpOwogICAgICAgIHQgPSAtKHcuZG90KHApKS9wLmRvdChiKTsKICAgICAgICBzID0gdy5kb3Qoeikvei5kb3QobC5iKTsKICAgICAgICByZXR1cm4gJ2knOwogICAgfQp9Owp2ZWN0b3I8IFZlYyA+IFYgOwppbnQgbWFpbigpIHsKI2lmZGVmIGtyeXB0b255dGUKICAgIGZyZW9wZW4oImluLnR4dCIsInIiLHN0ZGluICkgOwojZW5kaWYKICAgIGludCBuIDsKICAgIHNjYW5mKCIlZCIsJm4pIDsKICAgIHZlY3RvcjxWZWM+IFYgOwogICAgZm9yKCBpbnQgaSA9IDAgOyBpIDwgbiA7IGkrKyApIHsKICAgICAgICBkb3VibGUgeCAsIHkgOwogICAgICAgIHNjYW5mKCIlbGYlbGYiLCZ4LCZ5KSA7CiAgICAgICAgVmVjIHRtcCA9IFZlYyh4LHkpOwogICAgICAgIFYucHVzaF9iYWNrKCB0bXAgKSA7CiAgICB9CiAgICBpbnQgcXVlcnkgOwogICAgc2NhbmYoIiVkIiwmcXVlcnkgKSA7CiAgICBpbnQgYW5zID0gMCA7CiAgICBib29sIGYgPSAwIDsKICAgIHdoaWxlKCBxdWVyeS0tICkgewogICAgICAgIGludCBuMSxuMixuMyxuNCA7CiAgICAgICAgc2NhbmYoIiVkJWQlZCVkIiwmbjEsJm4yLCZuMywmbjQpIDsKICAgICAgICBpZiggIWYgKSB7CiAgICAgICAgICAgIG4xLS0gLG4yLS0sbjMtLSxuNC0tIDsKICAgICAgICAgICAgTGluZSBMMSA9IExpbmUoIFZbbjFdICwgVltuMl0gKSA7CiAgICAgICAgICAgIExpbmUgTDIgPSBMaW5lKCBWW24zXSAsIFZbbjRdICkgOwogICAgICAgICAgICBkb3VibGUgdCAsIHMgOwogICAgICAgICAgICBMMS5MaW5lQW5kTGluZUludGVyc2VjdGlvbjJEKEwyLHQscykgOwogICAgICAgICAgICBWZWMgcHQgPSBMMS5hdFBvcyh0KSA7CiAgICAgICAgICAgIGlmKCBmYWJzKHB0LnZhbFswXS0wKSA8IGVwcyAmJiBmYWJzKHB0LnZhbFsxXS0wKSA8IGVwcyApIHsKICAgICAgICAgICAgICAgIGYgPSAxIDsKICAgICAgICAgICAgfQogICAgICAgICAgICBhbnMgKysgOwogICAgICAgICAgICBWLnB1c2hfYmFjayhwdCkgOwogICAgICAgIH0KICAgIH0KICAgIGlmKCBmICljb3V0IDw8IGFucyA8PCAiXG4iIDsKICAgIGVsc2UgY291dCA8PCAwIDw8ICJcbiIgOwogICAgcmV0dXJuIDAgOwp9