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

int lccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //counter clockwise
    if(cross(b,c) <-EPS) return -1; //clockwise
    return 0;
}

bool intersectLL(const L& l, const L& m){
    return ( abs(cross(l[1]-l[0], m[1]-m[0])) > EPS ) ||
        ( abs(cross(l[1]-l[0], m[0]-l[0])) < EPS );
}
bool intersectLS(const L& l, const L& s){
    return cross(l[1]-l[0], s[0]-l[0])*
        cross(l[1]-l[0], s[1]-l[0]) < EPS;
}
bool intersectLP(const L& l, const P& p){
    return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) <= 0 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) <= 0 );
}
bool intersectSP(const L& s, const P& p){
    return abs(s[0]-p) +abs(s[1]-p) -abs(s[1]-s[0]) < 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);
}

double distanceLP(const L &l, const P &p) {
  return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
  if (intersectLS(l, s)) return 0;
  return min( distanceLP(l, s[0]), distanceLP(l, s[1]) );
}
double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0]-p), abs(s[1]-p));
}
double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

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

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