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 <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
};

namespace std{
    bool operator < (const P& a, const P& b){
        return (a.X != b.X) ? a.X<b.X : a.Y<b.Y;
    }
}

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;
    if(cross(b,c) <-EPS) return -1;
    if(dot(b,c) < EPS) return +2;
    if(norm(b) < norm(c)) return -2;
    return 0;
}

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]);
}

double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}

VP crosspointLC(const L &l, const C &c){
	VP ret;
	P mid = projection(l, c.p);
	double dlp = distanceLP(l, c.p);
	if(EQ(dlp, c.r)){
		ret.push_back(mid);
		return ret;
	}
	if(dlp > c.r){
		return ret;
	}
	P d = sqrt(c.r*c.r -dlp*dlp)/abs(l[1]-l[0]) *(l[1]-l[0]);
	ret.push_back(mid+d);
	ret.push_back(mid-d);
	return ret;
}
VP crosspointSC(const L &s, const C &c){
	VP ret;
	VP cp = crosspointLC(s,c);
	for(int i=0; i<(int)cp.size(); i++){
		if(dot(s[1]-s[0], cp[i]-s[0]) < 0) continue;
		if(norm(s[1]-s[0]) < norm(cp[i]-s[0])) continue;
		ret.push_back(cp[i]);
	}
	return ret;
}

double getangle(const P &p, const P &a, const P &b){ //clockwise
	P proj = projection(L(p,a), b);
	int minus = (dot(a-p, b-p)>=0)? 1 :-1;
	if(ccw(p,a,b)!=1){
		return atan2(abs(b-proj), minus*abs(p-proj));
	}else{
		return 2*M_PI - atan2(abs(b-proj), minus*abs(p-proj));
	}
}

int main(){
    while(1){
    	double l,r;
    	int n;
    	cin >> l >> r >> n;
    	r = r*2*M_PI;
    	if(n==0) break;
    	
    	VP v(n);
    	vector<L> e(n);
    	for(int i=0; i<n; i++){
    		int x,y;
    		cin >> x >> y;
    		v[i] = P(x,y);
    		e[i][1] = e[(i+1)%n][0] = P(x,y);
    	}
    	
    	P lead(0, l), follow(0, 0), fulc(0, 0);
    	bool change=false;
    	double angle_e = M_PI/2;
    	while(1){
    		double lenL = abs(lead-fulc);
    		double lenF = abs(follow-fulc);
    		P cp;
    		double rad = 2*M_PI;
    		int type = -1; //0:dot, 1:line
    		bool isL;
    		double newangle_e;
    		//lead
    		for(int i=0; i<n; i++){
    			if(EQ(v[i], fulc)) continue;
    			if(abs(v[i]-fulc) < lenL +EPS){ //inside of the circle
    				double angle = getangle(fulc, lead, v[i]);
    				if(angle < EPS) continue;
    				if(angle < rad+EPS){
    					if(EQ(angle,rad) && norm(cp-fulc)>norm(v[i]-fulc)){
    						continue;
    					}
    					cp = v[i];
    					type = 0;
    					rad = angle;
    					isL = true;
    				}
    			}
    		}
    		for(int i=0; i<n; i++){
    			VP c = crosspointSC(e[i], C(fulc, lenL));
    			for(int j=0; j<(int)c.size(); j++){
    				double angle = getangle(fulc, lead, c[j]);
    				if(angle<EPS) continue;
    				if(angle < rad+EPS){
    					if(EQ(angle,rad) && norm(cp-fulc)>norm(c[j]-fulc)){
    						continue;
    					}
    					cp = c[j];
    					type = 1;
    					rad = angle;
    					isL = true;
    					newangle_e = acos( fabs(dot(fulc-cp, e[i][0]-cp)) /
    						(abs(fulc-cp)*abs(e[i][0]-cp)));
    				}
    			}
    		}
    		//follow
    		for(int i=0; i<n; i++){
    			if(lenF == 0) break;
    			if(EQ(v[i], fulc)) continue;
    			if(abs(v[i]-fulc) < lenF +EPS){
    				double angle = getangle(fulc, follow, v[i]);
    				if(angle < EPS) continue;
    				if(angle < rad+EPS){
    					cp = v[i];
    					type = 0;
    					rad = angle;
    					isL = false;
    				}
    			}
    		}
    		for(int i=0; i<n; i++){
    			if(lenF == 0) break;
    			VP c = crosspointSC(e[i], C(fulc, lenF));
    			for(int j=0; j<(int)c.size(); j++){
    				double angle = getangle(fulc, follow, c[j]);
    				if(angle < EPS) continue;
    				if(angle < rad+EPS){
    					cp = c[j];
    					type = 1;
    					rad = angle;
    					isL = false;
    				}
    			}
    		}
    		
    		if(r < rad){
    			rad = r;
    			isL = false;
    			type = 0;
    		}
    		P rot(cos(rad), -sin(rad));
    		lead = fulc + (lead-fulc)*rot;
    		follow = fulc + (follow-fulc)*rot;
    		r -= rad;
    		//cerr << lead << " " << follow << " " << fulc << " " << type << endl;
    		if(type==0){
    			fulc = cp;
    		}else{
    			fulc = lead;
    			lead = follow;
    			follow = fulc;
    			change = !change;
    		}
    		if(!isL) break;
    		if(angle_e + rad < M_PI/2) break;
    		if(type==1){
    			angle_e = newangle_e;
    		}else{
    			angle_e = 2*M_PI;
    		}
    	}
    	
    	cout << fixed;
    	cout << setprecision(5);
    	if(change){
    		cout << lead.X << " " << lead.Y << endl;
    	}else{
    		cout << follow.X << " " << follow.Y << endl;
    	}
    }
    return 0;
}