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

#define EPS 1e-7

typedef complex<double> P;
typedef const P &rP;
typedef pair<double,double> pdd;

double pi;


double dot(rP va, rP vb){
	return real(va) * real(vb) + imag(va) * imag(vb);
}

double cross(rP va, rP vb){
	return real(va) * imag(vb) - imag(va) * real(vb);
}

bool contains(const vector<P> &plg, rP pt){
	int cnt = 0;
	double y = imag(pt);

	for(int i = 1; i < plg.size(); ++i){
		int j = i - 1;

		double dyi = imag(plg[i]) - y;
		double dyj = y - imag(plg[j]);
		double tx = (dyi * real(plg[j]) + dyj * real(plg[i])) / (dyi + dyj);

		if(imag(plg[i]) >= y && imag(plg[j]) < y){
			if( tx < real(pt) ) ++cnt;
		}
		else if(imag(plg[i]) < y && imag(plg[j]) >= y){
			if( tx < real(pt) ) ++cnt;
		}
	}
	
	return (cnt % 2 != 0);
}

vector<P> intersectsc(rP p1, rP p2, rP pc, double r){
	P v12 = p2 - p1;
	P v1c = pc - p1;
	
	vector<P> ret;

	double a = norm(v12);
	double b = dot(v12, v1c);
	double c = norm(v1c) - r * r;

	double D = b * b - a * c;
	if( D <= EPS ){
		return ret;
	}

	double t1 = (b + sqrt(D)) / a;
	double t2 = (b - sqrt(D)) / a;
	
	if(-EPS < t1 && t1 < 1.0 + EPS){
		ret.push_back(p1 + v12 * t1);
	}
	
	if(t1 != t2){
		if(-EPS < t2 && t2 < 1.0 + EPS){
			ret.push_back(p1 + v12 * t2);
		}
	}

	return ret;
}

double difangle(double base, double angle){
	angle -= base;
	while(angle < EPS){ angle += 2.0 * pi; }
	return angle;
}

bool cmp(const pdd &p, const pdd &q){
	if(abs(p.first - q.first) > EPS){
		return p.first < q.first;
	}
	return p.second > q.second;
}

P solve(double L, double R, const vector<P> &plg){
	R *= 2.0 * pi;

	P ea, eb(0.0, L);
	double flc = 0.0;
	
	bool ans_ea = true;

	P chkrot = polar(1.0, -EPS);

	while(R > EPS){
		P center = ea + flc * (eb - ea);

		if(flc > EPS && !contains(plg, (ea - center) * chkrot + center)){
			break;
		}
		if(!contains(plg, (eb - center) * chkrot + center)){
			break;
		}

		vector<pdd> info;
		info.push_back(pdd(R, flc));
		vector<P> ret;
		for(int i = 1; i < plg.size(); ++i){
			ret = intersectsc(plg[i-1], plg[i], center, L * flc);
			for(int j = 0; j < ret.size(); ++j){
				double angle = arg(ret[j] - center);
				double base = arg(ea - eb);
				double dif = difangle(angle, base);
				info.push_back(pdd(dif, 0.0));
			}
			
			ret = intersectsc(plg[i-1], plg[i], center, L * (1.0 - flc));
			for(int j = 0; j < ret.size(); ++j){
				double angle = arg(ret[j] - center);
				double base = arg(eb - ea);
				double dif = difangle(angle, base);
				info.push_back(pdd(dif, 1.0));
			}

			ret = intersectsc(ea, eb, center, abs(center - plg[i]));
			for(int j = 0; j < ret.size(); ++j){
				double angle = arg(ret[j] - center);
				double base = arg(plg[i] - center);
				double dif = difangle(base, angle);
				
				double rt = abs(ea - ret[j]) / L;
				if(abs(rt - flc) > EPS){
					info.push_back(pdd(dif, rt));
				}
			}
		}
		
		sort(info.begin(), info.end(), cmp);
		
		P rot = polar(1.0, -info[0].first);
		ea = (ea - center) * rot + center;
		eb = (eb - center) * rot + center;

		for(int i = 0; i < info.size(); ++i){
			if(abs(info[i].first - info[0].first) > EPS){ break; }
			if(info[i].second < flc){
				R = -1e10;
				break;
			}
		}

		R -= info[0].first;
		flc = info[0].second;

		if(abs(flc - 1.0) < EPS){
			swap(ea, eb);
			flc = 0.0;
			ans_ea = !ans_ea;
		}
	}

	return ans_ea ? ea : eb;
}

int main(){
	pi = acos(-1.0);
	
	double L, R;
	int n, x, y;
	while(scanf("%lf%lf%d", &L, &R, &n), n){
		vector<P> plg(n + 1);
		for(int i = 0; i < n; ++i){
			scanf("%d%d", &x, &y);
			plg[i] = P(x, y);
		}
		plg[n] = plg[0];
		
		P ans = solve(L, R, plg);
		printf("%f %f\n", real(ans), imag(ans));
	}
}