Problem: Dr. Asimov, a robotics researcher, has succeeded in developing a new robot. The robot can move freely along a special wire stretched around the floor. The robot always moves forward in a direction parallel to the current wire.

The good news is that this robot doesn't consume energy to move on the wire, regardless of its distance. However, in order to change the direction at the end point of the wire or the intersection of the wires, it is necessary to rotate around that point, and energy is consumed by the rotation angle.

I want to move this robot from the start point to the goal point. For example, in the figure below, place the robot at start in the east direction (the positive direction of the x-axis in the figure below) and move it to the goal. There is a route from start to the goal via intersection A and intersection B, and a route via intersection A and intersection C, but the former has a longer travel distance but a smaller rotation angle, so it consumes less energy.


<image>


Your job is to create a program that reads the position of the wires on the floor, the start point, the goal point, and reports the minimum total rotation angle required to move from the start point to the goal point.

The robot may be placed in any direction at the start point and in any direction at the goal point.



Input

The input consists of multiple datasets. The format of each dataset is as follows:


n
x11 y11 x21 y21
x12 y12 x22 y22
..
..
..
x1n y1n x2n y2n
sx sy gx gy


n is an integer indicating the number of wires. x1i y1i shows the coordinates of one end point of the i-th wire, and x2i y2i shows the coordinates of the other end point of the i-th wire.

sx sy and gx gy indicate the coordinates of the start point and the goal point, respectively.

All given coordinates are integer values, and the x-axis and y-axis values ​​are -1000 or more and 1000 or less. It may also be assumed that the start and finish points are on the end points of the given wire.

You can assume that n ≤ 50.

When n is 0, it indicates the end of input.

Output

For each dataset, output the minimum value of the total rotation angle on one line. If the robot cannot reach the goal point, output "-1". The output may contain an error of 0.00001 or less.

Example

Input

8
1 3 11 3
5 3 13 11
10 10 17 10
11 2 11 6
10 5 14 5
13 6 13 2
17 10 17 3
13 3 19 3
1 3 19 3
6
1 3 11 3
5 3 13 11
10 10 17 10
11 2 11 6
10 5 14 5
13 3 19 3
1 3 19 3
2
0 0 7 0
3 0 7 3
0 0 7 3
0


Output

270.0000
-1
36.86989765

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(a>b)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t> void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

using ld=long double;
using cm=complex<ld>;
#define x real()
#define y imag()
const ld eps=1e-8;
const ld PI=acos(ld(-1));
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}
auto cmcmp=[](const cm&a,const cm&b){
	if(sgn(a.x-b.x))return a.x<b.x;
	else return sgn(a.y-b.y)<0;
};
auto cmeq=[](const cm&a,const cm&b){
	return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;
};
ld dot(cm a,cm b){return a.x*b.x+a.y*b.y;}
ld crs(cm a,cm b){return a.x*b.y-a.y*b.x;}
ld crs(cm a,cm b,cm c){return crs(b-a,c-a);}
int ccw(cm a,cm b){return sgn(crs(a,b));}
int ccw(cm a,cm b,cm c){return ccw(b-a,c-a);}
//AOJ1183
int qeq(ld a,ld b,ld c,ld&d,ld&e){
	ld f=b*b-4*a*c;
	if(sgn(f)<0)return 0;
	ld g=sqrt(max(f,ld(0)));
	d=(-b+g)/(2*a);
	e=(-b-g)/(2*a);
	return sgn(f)+1;
}
//(-2)[a,-1](0)[b,1](2)
int bet(cm a,cm b,cm c){
	cm d=b-a;
	ld e=dot(d,c-a);
	if(sgn(e)<=0)return sgn(e)-1;
	return sgn(e-norm(d))+1;
}
//AOJ0153
//0-no,1-edge,2-in
int cont(cm a,cm b,cm c,cm d){
	if(ccw(a,b,c)==-1)
		swap(b,c);
	return min({ccw(a,b,d),ccw(b,c,d),ccw(c,a,d)})+1;
}
//AOJ1183
//arg between ab
//assume given lengths are valid
ld arg(ld a,ld b,ld c){
	return acos(min(max((a*a+b*b-c*c)/(2*a*b),ld(-1)),ld(1)));
}
//AOJ2233
//a->b->c と進むときに曲がる角度
//a-b-cが一直線上にあれば0が帰る
ld turn(cm a,cm b,cm c){
	return arg((c-b)/(b-a));
}

using ln=pair<cm,cm>;
cm dir(ln a){return a.b-a.a;}
cm eval(ln a,ld b){return a.a+dir(a)*b;}
int bet(ln a,cm b){return bet(a.a,a.b,b);}
cm proj(ln a,cm b){
	cm c=dir(a);
	return a.a+c*dot(c,b-a.a)/norm(c);
}
cm refl(ln a,cm b){
	return ld(2)*proj(a,b)-b;
}
//AOJ0153
ld dsp(ln a,cm b){
	cm c=proj(a,b);
	if(abs(bet(a.a,a.b,c))<=1)return abs(b-c);
	return min(abs(b-a.a),abs(b-a.b));
}
int ccw(ln a,cm b){return ccw(a.a,a.b,b);}
//AOJ1157
//0-no,1-yes(endpoint),2-yes(innner),3-overelap
int iss(ln a,ln b){
	int c1=ccw(a.a,a.b,b.a),c2=ccw(a.a,a.b,b.b);
	int d1=ccw(b.a,b.b,a.a),d2=ccw(b.a,b.b,a.b);
	if(c1||c2||d1||d2)return 1-max(c1*c2,d1*d2);
	int f=bet(a.a,a.b,b.a),g=bet(a.a,a.b,b.b);
	if(max(f,g)==-2||min(f,g)==2)return 0;
	return 3;
}
cm cll(ln a,ln b){
	return eval(a,crs(b.a,b.b,a.a)/crs(dir(a),dir(b)));
}
//AOJ1157
ld dss(ln a,ln b){
	if(iss(a,b))return 0;
	return min({dsp(a,b.a),dsp(a,b.b),dsp(b,a.a),dsp(b,a.b)});
}

bool inc(int a,int b,int c){return a<=b&&b<=c;}

template<class E,class D=ll>
vc<D> dijkstra(const vvc<E>& g,int s){
	const int n=g.size();
	using P=pair<D,int>;
	priority_queue<P,vc<P>,greater<P>> pq;
	vc<D> dist(n,1e9);
	const auto ar=[&](int v,D d){
		if(dist[v]>d){
			dist[v]=d;
			pq.push(P(d,v));
		}
	};
	ar(s,0);
	while(pq.size()){
		D d;
		int v;
		tie(d,v)=pq.top();pq.pop();
		for(auto e:g[v])
			ar(e.to,d+e.cost);
	}
	return dist;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	
	while(1){
		int n;cin>>n;
		if(n==0)break;
		
		vc<ln> w;
		rep(i,n){
			ld a,b,c,d;
			cin>>a>>b>>c>>d;
			w.eb(cm(a,b),cm(c,d));
		}
		
		vc<cm> pos;
		rep(i,n){
			pos.pb(w[i].a);
			pos.pb(w[i].b);
		}
		
		rep(i,n)rep(j,i){
			if(inc(1,iss(w[i],w[j]),2))
				pos.pb(cll(w[i],w[j]));
		}
		
		sort(all(pos),cmcmp);
		pos.erase(unique(all(pos),cmeq),pos.ed);
		const auto idx=[&](cm a){
			return lower_bound(all(pos),a,cmcmp)-pos.bg;
		};
		
		int s=pos.size();
		vvc<pi> g(s);
		int m=0;
		rep(i,n){
			vc<cm> z{w[i].a,w[i].b};
			rep(j,n)if(i!=j){
				int a=iss(w[i],w[j]);
				if(a==1||a==2){
					z.pb(cll(w[i],w[j]));
				}
				if(a==3){
					if(bet(w[i],w[j].a)==0)
						z.pb(w[j].a);
					if(bet(w[i],w[j].b)==0)
						z.pb(w[j].b);
				}
			}
			sort(all(z),[&](cm a,cm b){return norm(a-w[i].a)<norm(b-w[i].a);});
			z.erase(unique(all(z),cmeq),z.ed);
			rep(j,int(z.size())-1){
				int a=idx(z[j]),b=idx(z[j+1]);
				g[a].eb(b,m++);
				g[b].eb(a,m++);
			}
		}
		
		struct E{int to;ld cost;};
		vvc<E> gg(m+2);
		rep(i,s){
			for(auto e:g[i]){
				for(auto f:g[i]){
					gg[e.b^1].pb(E{f.b,abs(turn(pos[e.a],pos[i],pos[f.a]))});
				}
			}
		}
		
		ld sx,sy,tx,ty;
		cin>>sx>>sy>>tx>>ty;
		int a=idx(cm(sx,sy)),b=idx(cm(tx,ty));
		for(auto e:g[a])
			gg[m].pb(E{e.b,0});
		for(auto e:g[b])
			gg[e.b^1].pb(E{m+1,0});
		
		ld ans=dijkstra<E,ld>(gg,m)[m+1]/PI*180;
		if(ans>1e9)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
}