#include <algorithm> 
#include <bitset> 
#include <cctype> 
#include <complex> 
#include <cmath> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <ctime> 
#include <deque> 
#include <functional> 
#include <iomanip> 
#include <iostream> 
#include <list> 
#include <map> 
#include <numeric> 
#include <queue> 
#include <set> 
#include <sstream> 
#include <stack> 
#include <string> 
#include <utility> 
#include <vector> 
  
using namespace std; 
  
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} 
template<class T> inline T sqr(T x) {return x*x;} 
  
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<string> vs; 
typedef pair<int, int> pii; 
typedef long long ll; 
  
#define all(a)  (a).begin(),(a).end() 
#define rall(a) (a).rbegin(), (a).rend() 
#define pb push_back 
#define mp make_pair 
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) 
#define exist(s,e) ((s).find(e)!=(s).end()) 
#define range(i,a,b) for(int i=(a);i<(b);++i) 
#define rep(i,n)  range(i,0,n) 
#define clr(a,b) memset((a), (b) ,sizeof(a)) 
#define dump(x)  cerr << #x << " = " << (x) << endl; 
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
  
  
const double eps = 1e-10; 
const double pi  = acos(-1.0); 
const ll INF =1LL << 62; 
const int inf =1 << 30; 
  
  
// テ、ツサツ・テ、ツクツ?テ・ツケツセテ、ツスツ陛ゥツδィテ・ツ按?
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;} 
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;} 
#define x real() 
#define y imag() 
#define mp make_pair 
  
typedef bool B; 
typedef long double D; 
typedef complex<D> P; 
typedef pair <P,P> L; 
typedef struct {P c;D r;} C; 
typedef struct {P c;D a,b;} E; // テヲツ・ツ陛・ツ??」ツつづィツソツステ・ツ環?、ツコツ暗・ツョツ?
typedef vector <P>Pol; 
  
// テ」ツつステ」ツδシテ」ツδ暗」ツ?ョテ」ツつュテ」ツδシ 
B cmp_x(const P &a,const P &b){ return (abs(a.x-b.x)<eps ) ?  a.y<b.y : a.x<b.x;}  // base x 
B cmp_y(const P &a,const P &b){ return (abs(a.y-b.y)<eps ) ?  a.x<b.x : a.y<b.y;}  // base y 
B cmp_a(const P &a,const P &b){ return (abs(arg(a)-arg(b))<eps ) ?  norm(a) < norm(b) : arg(a)<arg(b);} // base arg 
  
  
// テ・ツ淞コテヲツ慊ャテヲツ督催、ツスツ?
// verify 
D ip(P a, P b) {return a.x * b.x + a.y * b.y;} 
D ep(P a, P b) {return a.x * b.y - a.y * b.x;} 
D sr(D a) {return sqrt(max(a, (D)0));} 
P vec(L l){return l.second-l.first;} 
  
  
// テァツつケ 
D ang (P p){return arg(p);} 
D ang (P base, P a, P b) {return arg( (b - base) / (a - base) );} // base テ、ツクツュテ・ツソツ?
P rot (P base, P a, D theta){return base+polar( abs(a-base), arg(a-base)+theta );} 
  
  
// ccw  
enum CCW{FRONT = 1, RIGHT = 2, BACK = 4, LEFT = 8, MID = 16, ON=FRONT|BACK|MID }; 
  
int ccw(P base, P a, P b) {              //テァツつケaテ」ツ?ィテァツつケbテ」ツ?古、ツクツ偲」ツ?暗」ツつ嘉」ツつ古」ツ?淌・ツ閉湘」ツ??」ツ?ォ 
  a -= base; b -= base; 
  if (ep(a, b) > 0)       return LEFT;    // counter clockwise 
  if (ep(a, b) < 0)      return RIGHT;   // clockwise 
  if (ip(a, b) < 0)      return BACK;    // b--base--a on line 
  if (norm(a) < norm(b)) return FRONT;   // base--a--b on line 
                         return MID;      // base--b--a on line  aテ」ツ?ィbテ」ツ?ョテァツキツ堙・ツ按?・ツ按、テ・ツョツ堙」ツ?ッテ」ツ?禿」ツつ?
} 
  
  
  
B iver(L a, L b) {return ip(vec(a),vec(b) )== 0.0;} 
B ipar(L a, L b) {return ep(vec(a),vec(b) )== 0.0;} 
  
  
// テ、ツコツ、テァツつケ 
P pLL(L a,L b){ return a.first+vec(a)*ep(vec(b),b.first-a.first)/ep(vec(b), vec(a));} 
  
  
// テァツつケテ」ツ?ィテァツ崢エテァツキツ堙」ツ?ィテァツキツ堙・ツ按?ゥツ鳴「テゥツ?」テ」ツ?ョテ、ツコツ、テ・ツキツョテ・ツ按、テ・ツョツ?
  
B iLL(L l1,L l2){ return !ipar(l1,l2);} 
B eqL(L a, L b) {return !iLL(a, b) && ep(vec(a), b.first - a.first)==0;} 
B iLS(L a, L b)  {return sig(ep(vec(a), b.first - a.first)) * sig(ep(vec(a), b.second - a.first)) <= 0;} 
B iLSs(L a, L b) {return sig(ep(vec(a), b.first - a.first)) * sig(ep(vec(a), b.second - a.first)) <  0;} 
B iSS(L a, L b) { 
    int cwa = ccw(a.first,a.second, b.first) | ccw(a.first,a.second, b.second); 
    int cwb = ccw(b.first,b.second, a.first) | ccw(b.first,b.second, a.second); 
    return ((cwa | cwb) & MID) || ((cwa & cwb) == (LEFT | RIGHT)); 
} 
B iSSs(L a, L b) { 
    int cwa = ccw(a.first,a.second, b.first) | ccw(a.first,a.second, b.second); 
    int cwb = ccw(b.first,b.second, a.first) | ccw(b.first,b.second, a.second); 
    return (cwa & cwb) == (LEFT | RIGHT); 
} 
  
// テァツつケテ」ツ?ィテァツ崢エテァツキツ堙」ツ?ィテァツキツ堙・ツ按?ゥツ鳴「テゥツ?」テ」ツ?ョティツキツ敕ゥツ崢「 
  
D dLP(L l,P p){ return ep(vec(l),p-l.first)/abs(vec(l));} 
D dSP(L s,P p){ 
    if (sig( ip( vec(s), p - s.first)) <= 0) return abs(p - s.first); 
    if (sig( ip(-vec(s), p - s.second)) <= 0) return abs(p - s.second); 
    return dLP(s,p); 
} 
D dLL(L a,L b){ return iLL(a,b) ? 0 : dLP(a,b.first);} 
D dLS(L a,L b){ return iLS(a,b) ? 0 : min(dLP(a, b.first), dLP(a, b.second));} 
D dSS(L a,L b){ return iSS(a,b) ? 0 : min( min(dSP(a,b.first),dSP(a,b.second)),min(dSP(b,a.first),dSP(b,a.second)));} 
  

struct star{
	L l[5];
};

int main(void){
    int n,m,l;
	while(cin >> n,n){
		D graph[110][110];

		rep(i,n)rep(j,n) graph[i][j]=INF;

		star s[110];

		cin >> m >> l;
		m--;l--;
		rep(i,n){
			P base;
			cin >> base.x >> base.y;
			D angle;
			cin >> angle;
			D r;
			cin >> r;

			P points[5];

			points[0]=base;
			points[0].y+=r;

			for(int j=1;j<5;j++){
				D theta=1.0*72/180.0*pi;
				points[j]=rot(base,points[0],theta*j);
			}
			rep(j,5){
				D theta=angle/180.0*pi;
				points[j]=rot(base,points[j],theta);
			}
		
			rep(j,5){
				int pre=(2*j)%5,post=(2*j+2)%5;
				s[i].l[j]=mp(points[pre],points[post]);
			}
		}
		
		rep(i,n)rep(j,n){
			D cmin=INF;
			rep(k,5)rep(l,5){
				cmin=min(cmin,abs( dSS(s[i].l[k],s[j].l[l] )));
			}
			graph[i][j]=cmin;
		}

		rep(k,n)rep(i,n)rep(j,n){
			graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
		}

		cout.precision(9);
		cout << fixed << graph[m][l] << endl;
	}
    return 0; 
}