Problem: Let's think about a bar rotating clockwise as if it were a twirling baton moving on a planar surface surrounded by a polygonal wall (see Figure 1).

<image>


Figure 1. A bar rotating in a polygon

Initially, an end of the bar (called "end A") is at (0,0), and the other end (called "end B") is at (0,L) where L is the length of the bar. Initially, the bar is touching the wall only at the end A.

The bar turns fixing a touching point as the center. The center changes as a new point touches the wall.

Your task is to calculate the coordinates of the end A when the bar has fully turned by the given count R.

<image>


Figure 2. Examples of turning bars

In Figure 2, some examples are shown. In cases (D) and (E), the bar is stuck prematurely (cannot rotate clockwise anymore with any point touching the wall as the center) before R rotations. In such cases, you should answer the coordinates of the end A in that (stuck) position.

You can assume the following:

> When the bar's length L changes by ε (|ε| < 0.00001), the final (x,y) coordinates will not change more than 0.0005.

Input

The input consists of multiple datasets. The number of datasets is no more than 100. The end of the input is represented by "0 0 0".

The format of each dataset is as follows:


L R N
X1 Y1
X2 Y2
...
XN YN


L is the length of the bar. The bar rotates 2π× R radians (if it is not stuck prematurely). N is the number of vertices which make the polygon.

The vertices of the polygon are arranged in a counter-clockwise order. You may assume that the polygon is simple, that is, its border never crosses or touches itself.

N, Xi and Yi are integer numbers; R and L are decimal fractions. Ranges of those values are as follows:


1.0 ≤ L ≤ 500.0,
1.0 ≤ R ≤ 10.0,
3 ≤ N ≤ 100,
-1000 ≤ Xi ≤ 1000,
-1000 ≤ Yi ≤ 1000,



X1 ≤ -1,  Y1 = 0,
X2 ≥ 1,  Y2 = 0.


Output

For each dataset, print one line containing x- and y-coordinates of the final position of the end A, separated by a space. The value may contain an error less than or equal to 0.001. You may print any number of digits after the decimal point.

Sample Input


4.0 2.0 8
-1 0
5 0
5 -2
7 -2
7 0
18 0
18 6
-1 6
4.0 2.0 4
-1 0
10 0
10 12
-1 12
4.0 1.0 7
-1 0
2 0
-1 -3
-1 -8
6 -8
6 6
-1 6
4.0 2.0 6
-1 0
10 0
10 3
7 3
7 5
-1 5
5.0 2.0 6
-1 0
2 0
2 -4
6 -4
6 6
-1 6
6.0 1.0 8
-1 0
8 0
7 2
9 2
8 4
11 4
11 12
-1 12
0 0 0


Output for the Sample Input


16.0 0.0
9.999999999999998 7.4641016151377535
0.585786437626906 -5.414213562373095
8.0 0.0
6.0 0.0
9.52786404500042 4.0


Note that the above sample input corresponds to the cases in Figure 2. For convenience, in Figure 3, we will show an animation and corresponding photographic playback for the case (C).

<image>
<image> | <image> | <image> | <image> | <image> | <image> | <image> | <image> | <image>
---|---|---|---|---|---|---|---|---

Figure 3. Animation and photographic playback for case (C)





Example

Input

4.0 2.0 8
-1 0
5 0
5 -2
7 -2
7 0
18 0
18 6
-1 6
4.0 2.0 4
-1 0
10 0
10 12
-1 12
4.0 1.0 7
-1 0
2 0
-1 -3
-1 -8
6 -8
6 6
-1 6
4.0 2.0 6
-1 0
10 0
10 3
7 3
7 5
-1 5
5.0 2.0 6
-1 0
2 0
2 -4
6 -4
6 6
-1 6
6.0 1.0 8
-1 0
8 0
7 2
9 2
8 4
11 4
11 12
-1 12
0 0 0


Output

16.0 0.0
9.999999999999998 7.4641016151377535
0.585786437626906 -5.414213562373095
8.0 0.0
6.0 0.0
9.52786404500042 4.0

Solution (in CPP):

Solution:
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
double dSP(Pt a, Pt b, Pt c) {
	if (sig((b - a).dot(c - a)) <= 0) return (c - a).ABS();
	if (sig((a - b).dot(c - b)) <= 0) return (c - b).ABS();
	return ABS(tri(a, b, c)) / (b - a).ABS();
}
bool iCS(Pt a, double r, Pt b, Pt c) {
	return (sig(r - dSP(b, c, a)) >= 0 && sig(r - max((b - a).ABS(), (c - a).ABS())) <= 0);
}
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
bool iSSstrict(Pt a, Pt b, Pt c, Pt d) {
	return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0);
}
pair<Pt,Pt> pCL(Pt a, double r, Pt b, Pt c) {
	Pt h = b + (c - b) * (c - b).dot(a - b) / (c - b).abs2(); // perp(b, c, a)
	double d = (h - a).ABS();
	double y = sqrt(max(r * r - d * d, 0.0));
	Pt e = (c - b) / (c - b).ABS();
	return make_pair(h - e * y, h + e * y);
}
double EPS2=1e-6;
Pt p[110];
int n;
//inside: +1 on: 0 outside: -1
int sGP(Pt a) {
	int side = -1, i;
	for (i = 0; i < n; ++i) {
		Pt p0 = p[i] - a, p1 = p[i + 1] - a;
		if (sig(p0.det(p1)) == 0 && sig(p0.dot(p1)) <= 0) return 0;
		if (p0.y > p1.y) swap(p0, p1);
		if (sig(p0.y) <= 0 && 0 < sig(p1.y) && sig(p0.det(p1)) > 0) side = -side;
	}
	return side;
}
int main(){
	double L,R;
	int a;
	while(scanf("%lf%lf%d",&L,&R,&a),a){
		R*=PI*2;
		n=a;
		for(int i=0;i<a;i++){
			double x,y;
			scanf("%lf%lf",&x,&y);
			p[i]=Pt(x,y);
		}
		p[a]=p[0];
		for(int i=0;i<=a;i++)p[i]=p[i]*Pt(cos(1),sin(1));
		Pt s=Pt(0,0);
		Pt t=Pt(0,L)*Pt(cos(1),sin(1));
		Pt c=s;
		double d=(s-t).arg();
		int last=0;
		while(1){
			Pt vs=s-c;
			double sr=vs.ABS();
			Pt vt=t-c;
			double tr=vt.ABS();
			double val=9999999;
			Pt to=Pt(0,0);
			vector<Pt>e;
			for(int i=0;i<a;i++){
				if(sig((p[i]-c).ABS())&&(p[i]-c).ABS()<sr){
					e.push_back(p[i]);
				}
				if(iCS(c,sr,p[i],p[(i+1)%a])){
					pair<Pt,Pt> t1=pCL(c,sr,p[i],p[(i+1)%a]);
					
					//printf("%f %f, %f %f\n",t1.first.x,t1.first.y,t1.second.x,t1.second.y);
					double lb=0;
					double rb=(p[i+1]-p[i]).ABS();
					if((p[i]-t1.first).dot(p[i+1]-t1.first)<=EPS)e.push_back(t1.first);
					if((p[i]-t1.second).dot(p[i+1]-t1.second)<=EPS)e.push_back(t1.second);
				}
			}
			
			for(int i=0;i<e.size();i++){
				Pt pe=e[i]*Pt(cos(-1),sin(-1));
		//		printf("%f %f\n",pe.x,pe.y);
				if(!sig(sr))continue;
		//		if((e[i]-c).ABS()<sr){
					if(sig((e[i]-c).ABS())){
						double th=(e[i]-c).arg();
						if(!sig(th-d)){
							Pt tmp=c+(e[i]-c)*Pt(cos(EPS2),-sin(EPS2));
							bool out=false;
							if(sGP(tmp)==-1)out=true;
							for(int j=0;j<a;j++)if(iSSstrict(c,tmp,p[j],p[j+1])){out=true;}
							if(out){
								th=d;
								
							}else th=d-PI*2;
						}else if(th>d)th-=PI*2;
						if(val>d-th||(val+EPS>d-th&&(e[i]-c).ABS()>(to-c).ABS())){
							to=e[i];
							val=d-th;
						}
			//			printf("%f, %f: %f %f\n",e[i].x,e[i].y,th,val);
					}
		//		}
			}
			e.clear();
			for(int i=0;i<a;i++){
				if(sig((p[i]-c).ABS())&&(p[i]-c).ABS()<tr){
					e.push_back(p[i]);
				}
				if(iCS(c,tr,p[i],p[(i+1)%a])){
					pair<Pt,Pt> t1=pCL(c,tr,p[i],p[(i+1)%a]);
					if((p[i]-t1.first).dot(p[i+1]-t1.first)<=EPS)e.push_back(t1.first);
					if((p[i]-t1.second).dot(p[i+1]-t1.second)<=EPS)e.push_back(t1.second);	
				}
			}
			double d2=d+PI;
			if(d2>=PI)d2-=PI*2;
			for(int i=0;i<e.size();i++){
				if(!sig(tr))continue;
		//		if((e[i]-c).ABS()<tr){
					if(sig((e[i]-c).ABS())){
						double th=(e[i]-c).arg();
						if(!sig(th-d2)){
							Pt tmp=c+(e[i]-c)*Pt(cos(EPS2),-sin(EPS2));
							bool out=false;
							if(sGP(tmp)==-1)out=true;
							for(int j=0;j<a;j++)if(iSSstrict(c,tmp,p[j],p[j+1])){out=true;}
							if(out){
								th=d2;
								
							}else th=d2-PI*2;
						}else if(th>d2)th-=PI*2;
						if(val>d2-th||(val+EPS>d2-th&&(e[i]-c).ABS()>(to-c).ABS())){
							to=e[i];
							val=d2-th;
						}
			//			printf("%f, %f: %f %f\n",e[i].x,e[i].y,th,val);
					}
		//		}
			}
			if(val>R){
				val=R;
			}
			if(sig(val))last=0;
			last++;
			if(last>110)break;
			vs=vs*Pt(cos(val),-sin(val));
			vt=vt*Pt(cos(val),-sin(val));
			d-=val;
			if(d<=-PI)d+=2*PI;
			s=c+vs;
			t=c+vt;
			c=to;
			Pt ps=s*Pt(cos(-1),sin(-1));
			Pt pt=t*Pt(cos(-1),sin(-1));
			Pt pc=c*Pt(cos(-1),sin(-1));
		//	printf("(%f, %f) (%f, %f): %f (%f, %f)\n",ps.x,ps.y,pt.x,pt.y,val,pc.x,pc.y);
			R-=val;
			if(sig(R)!=1)break;
		}
		s=s*Pt(cos(-1),sin(-1));
		printf("%.12f %.12f\n",s.x,s.y);
	}
}