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 <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>
namespace lc {
static const double EPS = 1e-9;
inline double abs(double x){ return std::abs(x); }
}
namespace lc {
struct Point {
	double x;
	double y;
	explicit Point(const double &x = 0.0, const double &y = 0.0) :
		x(x), y(y)
	{ }
	Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
	Point &operator+=(const Point &p){ return *this = *this + p; }
	Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
	Point operator*(double s) const { return Point(x * s, y * s); }
	Point operator*(const Point &p) const {
		return Point(x * p.x - y * p.y, x * p.y + y * p.x);
	}
	Point operator/(double s) const { return Point(x / s, y / s); }
	double abs() const { return sqrt(x * x + y * y); }
	double norm() const { return x * x + y * y; }
	Point unit() const { return *this / abs(); }
	Point ortho() const { return Point(-y, x); }
	double arg() const { return atan2(y, x); }
};
inline Point operator*(double s, const Point &p){ return p * s; }
inline double cross(const Point &a, const Point &b){
	return a.x * b.y - a.y * b.x;
}
inline double dot(const Point &a, const Point &b){
	return a.x * b.x + a.y * b.y;
}
inline int ccw(const Point &a, const Point &b, const Point &c){
	Point d = b - a, e = c - a;
	if(cross(d, e) > 0.0){ return 1; }
	if(cross(d, e) < 0.0){ return -1; }
	if(dot(d, e) < 0.0){ return 2; }
	if(d.abs() < e.abs()){ return -2; }
	return 0;
}
}
namespace lc {
struct Line {
	Point a;
	Point b;
	explicit Line(const Point &a = Point(), const Point &b = Point()) :
		a(a), b(b)
	{ }
	Point projection(const Point &p) const {
		double t = dot(p - a, b - a) / (b - a).norm();
		return a + t * (b - a);
	}
	Point direction() const {
		return (b - a).unit();
	}
};
inline bool tolerant_eq(const Line &a, const Line &b){
	const double x = abs(cross(a.b - a.a, b.b - b.a));
	const double y = abs(cross(a.b - a.a, a.b - b.a));
	return x < EPS && y < EPS;
}
inline int ccw(const Line &l, const Point &p){
	return ccw(l.a, l.b, p);
}
}
namespace lc {
struct Segment {
	Point a;
	Point b;
	explicit Segment(const Point &a = Point(), const Point &b = Point()) :
		a(a), b(b)
	{ }
	Line to_line() const { return Line(a, b); }
	double length() const { return (b - a).abs(); }
	Point direction() const {
		return (b - a).unit();
	}
};
}
namespace lc {
struct Circle {
	Point c;
	double r;
	explicit Circle(const Point &c = Point(), double r = 0.0) :
		c(c), r(r)
	{ }
	int contains(const Point &p) const {
		const double d2 = (p - c).norm(), r2 = r * r;
		if(d2 > r2){ return 0; }
		if(d2 < r2){ return 1; }
		return -1;
	}
};
}
namespace lc {
inline bool intersect(const Point &a, const Line &b){
	return abs(cross(b.b - a, b.a - a)) < EPS;
}
inline bool intersect(const Line &a, const Point &b){
	return intersect(b, a);
}
inline bool intersect(const Point &a, const Segment &b){
	return (b.a - a).abs() + (b.b - a).abs() - (b.b - b.a).abs() < EPS;
}
inline bool intersect(const Segment &a, const Point &b){
	return intersect(b, a);
}
}
namespace lc {
inline std::vector<Point> crossing_points(const Line &l, const Circle &c){
	const Point &p = l.projection(c.c);
	const double t = (p - c.c).abs();
	if(t > c.r + EPS){ return std::vector<Point>(); }
	if(t > c.r - EPS){ return std::vector<Point>(1, p); }
	const Point v = l.direction();
	const double d = sqrt(c.r * c.r - t * t);
	return std::vector<Point>({ p + d * v, p - d * v });
}
inline std::vector<Point> crossing_points(const Segment &s, const Circle &c){
	const std::vector<Point> cps(crossing_points(s.to_line(), c));
	std::vector<Point> result;
	for(const auto &p : cps){
		if(intersect(s, p)){ result.push_back(p); }
	}
	return result;
}
}
using namespace std;
static const double EPS = lc::EPS;
pair<double, double> solve(
	const lc::Segment &bar, const vector<lc::Point> &poly)
{
	if(bar.length() < EPS){ return make_pair(2.0 * M_PI, 0.0); }
	const int n = poly.size();
	const lc::Circle c(bar.a, bar.length());
	const double base_arg = bar.direction().arg();
	double min_rot = 2.0 * M_PI, max_dist = 0.0;
	for(int i = 0; i < n; ++i){
		const lc::Segment edge(poly[i], poly[(i + 1) % n]);
		auto cps = crossing_points(edge, c);
		if(c.contains(edge.a)){ cps.push_back(edge.a); }
		if(c.contains(edge.b)){ cps.push_back(edge.b); }
		for(const auto &p : cps){
			if((p - bar.a).abs() < EPS){ continue; }
			double arg = base_arg - (p - bar.a).arg();
			while(arg <= -EPS){ arg += 2.0 * M_PI; }
			if(abs(arg) < EPS){
				const lc::Line ortho(
					bar.b + bar.direction().ortho(), bar.b);
				if(lc::tolerant_eq(bar.to_line(), edge.to_line())){
					arg = 2.0 * M_PI;
				}else if(
					!lc::intersect(bar.to_line(), edge.a) &&
					lc::ccw(bar.to_line(), edge.a) == -1)
				{
					if(lc::ccw(ortho, edge.a) != -1){ arg = 2.0 * M_PI; }
				}else if(
					!lc::intersect(bar.to_line(), edge.b) &&
					lc::ccw(bar.to_line(), edge.b) == -1)
				{
					if(lc::ccw(ortho, edge.b) != -1){ arg = 2.0 * M_PI; }
				}else{
					arg = 2.0 * M_PI;
				}
			}
			if(arg < min_rot){
				min_rot = arg;
				max_dist = (p - bar.a).abs();
			}else if(arg == min_rot){
				max_dist = max(max_dist, (p - bar.a).abs());
			}
		}
	}
	return make_pair(min_rot, max_dist);
}
int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	while(true){
		double l, r;
		int n;
		cin >> l >> r >> n;
		if(l == 0.0 && r == 0.0 && n == 0){ break; }
		vector<lc::Point> outline(n);
		for(int i = 0; i < n; ++i){ cin >> outline[i].x >> outline[i].y; }
		lc::Segment bar[2] = {
			lc::Segment(lc::Point(0, 0), lc::Point(0, l)),
			lc::Segment(lc::Point(0, 0), lc::Point(0, 0))
		};
		int flip = 0;
		r *= 2.0 * M_PI;
		while(r > EPS){
			const auto head_ret = solve(bar[0], outline);
			const auto tail_ret = solve(bar[1], outline);
			const double rot = min(r, min(head_ret.first, tail_ret.first));
			if(rot < EPS){ break; }
			const lc::Point trans_rot(cos(rot), -sin(rot));
			for(int i = 0; i < 2; ++i){
				if(bar[i].length() < EPS){ continue; }
				bar[i].b = bar[i].a + (bar[i].b - bar[i].a) * trans_rot;
			}
			const double shift =
				head_ret.first <= tail_ret.first ?
					head_ret.second : -tail_ret.second;
			const lc::Point trans_shift = (bar[0].b - bar[1].b).unit() * shift;
			bar[0].a += trans_shift;
			bar[1].a += trans_shift;
			if(bar[0].length() < EPS){
				swap(bar[0], bar[1]);
				flip = 1 - flip;
			}
			r -= rot;
		}
		const lc::Point answer = bar[1 - flip].b;
		cout << answer.x << " " << answer.y << endl;
	}
	return 0;
}