#include <iostream>
#include <cstdio>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};

struct poly_connect{
    VP v;
    vector<int> c;
};

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) < -EPS) return -1; //cw
    if(dot(b,c) < -EPS) return +2; //c-a-b
    if(abs(c)-abs(b) > EPS) return -2; //a-b-c
    return 0; //a-c-b
}

bool intersectSP(const L& s, const P &p){
    return abs(cross(s[0]-p, s[1]-p))<EPS  && dot(s[0]-p, s[1]-p)<EPS;
}
P projection(const L& l, const P& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L& l, const P& p) {
  return p + 2.0*(projection(l, p) -p);
}
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B/A *(m[1]-m[0]);
}
int in_poly(const P &p, const VP &poly){
    int n = poly.size();
    int ret = -1;
    for(int i=0; i<n; i++){
        P a = poly[i]-p;
        P b = poly[(i+1)%n]-p;
        if(a.Y > b.Y) swap(a,b);
        if(intersectSP(L(a,b), P(0,0))) return 0;
        if(a.Y<=0 && b.Y>0 && cross(a,b)<0) ret = -ret;
    }
    return ret;
}
bool convex_overlap(const VP &a, const VP &b){
    for(P p : a){
        if(in_poly(p, b) > 0) return true;
    }
    for(P p : b){
        if(in_poly(p, a) > 0) return true;
    }
    if(in_poly((a[0] +a[1] +a[2])/3.0, b) > 0 ||
       in_poly((b[0] +b[1] +b[2])/3.0, a) > 0){
        return true;
    }
    return false;
}

poly_connect fold_convex(int numl, int idx, poly_connect pc, const L& l){
    poly_connect ret;
    int n = pc.v.size();
    for(int i=0; i<n; i++){
        P curr = pc.v[i];
        P next = pc.v[(i+1)%n];
        if(ccw(l[0], l[1], curr) != -1){
            ret.v.push_back(curr);
            ret.c.push_back(pc.c[i]);
        }
        if(ccw(l[0], l[1], curr) *ccw(l[0], l[1], next) == -1){
            ret.v.push_back(crosspointLL(L(curr, next), l));
            if(ccw(l[0], l[1], curr) != -1){
                ret.c.push_back(2*numl-1-idx);
            }else{
                ret.c.push_back(pc.c[i]);
            }
        }
    }
    return ret;
}

poly_connect reverse_layer(int numl, poly_connect pc, const L &l){
    int n = pc.v.size();
    if(n == 0) return pc;
    for(int i=0; i<n; i++){
        pc.v[i] = reflection(l, pc.v[i]);
        if(pc.c[i] != -1){
            pc.c[i] = 2*numl -1 -pc.c[i];
        }
    }
    reverse(pc.v.begin()+1, pc.v.end());
    reverse(pc.c.begin(), pc.c.end());
    return pc;
}

void recursive_fold(int numl, int idx, vector<poly_connect> &ulayer, vector<bool> &used){
    if(idx >= numl || used[idx]) return;
    used[idx] = true;
    for(int connect : ulayer[idx].c){
        if(connect != -1){
            recursive_fold(numl, connect, ulayer, used);
        }
    }
    for(int i=idx+1; i<numl; i++){
        if(!ulayer[i].v.empty() && convex_overlap(ulayer[idx].v, ulayer[i].v)){
            recursive_fold(numl, i, ulayer, used);
        }
    }
}

void fold(int numl, vector<poly_connect> &layer, const P &p, const P &q){
    vector<poly_connect> dlayer(512), ulayer(512);
    P mid = (p +q) /2.0;
    L bisec(mid, mid +(q -p) *P(0, -1)); //残す方
    L rbisec(bisec[1], bisec[0]);
    for(int i=0; i<numl; i++){
        dlayer[i] = fold_convex(numl, i, layer[i], bisec);
        ulayer[i] = fold_convex(numl, i, layer[i], rbisec);
    }
    vector<bool> used(512, false);
    for(int i=numl-1; i>=0; i--){
        //一番上にあるlayerから再帰的に始める
        if(in_poly(p, layer[i].v) > 0){
            recursive_fold(numl, i, ulayer, used);
            break;
        }
    }
    for(int i=0; i<numl; i++){
        if(used[i]){
            layer[i] = dlayer[i];
            layer[2*numl-1-i] = reverse_layer(numl, ulayer[i], bisec);
        }
    }
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

        VP p(n), q(n);
        for(int i=0; i<n; i++){
            int px,py, qx,qy;
            cin >> px >> py >> qx >> qy;
            p[i] = P(px, py);
            q[i] = P(qx, qy);
        }
        int hx,hy;
        cin >> hx >> hy;
        P h(hx, hy);

        vector<poly_connect> layer(1024);
        layer[0].v = VP{P(0, 0), P(100, 0), P(100, 100), P(0, 100)};
        layer[0].c = vector<int>{-1, -1, -1, -1};
        for(int i=0; i<n; i++){ 
            fold(1<<i, layer, p[i], q[i]);
        }
        int ans = 0;
        for(int i=0; i<(1<<n); i++){
            if(in_poly(h, layer[i].v) > 0){
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3416