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<bits/stdc++.h>
#define inf 1<<29
#define linf 1e16
#define eps (1e-6)
#define mod 1000000007
#define pi acos(-1)
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
};
typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c=Point(),double r=0.0):c(c),r(r){}
};

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}
double arg(Vector p){ return atan2(p.y,p.x);}
Vector polar(double a,double r){ return Point(cos(r)*a,sin(r)*a);}

bool in(Circle c,Point p){
  if(abs(c.c-p)-c.r<eps)return true;
  return false;
}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

bool intersect(Circle c,Line L){
  if(getDistanceLP(L,c.c)-c.r<eps)return true;
  return false;
}

pair<Point,Point> getCrossPoints(Circle c,Line l){
  Vector pr=project(l,c.c);
  Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
  double base=sqrt(c.r*c.r-norm(pr-c.c));
  return mp(pr+e*base,pr-e*base);
}

vector<Point> getCrossPoint(Circle c,Line l){
  vector<Point> res;
  pair<Point,Point> pp=getCrossPoints(c,l);
  if(in(c,l.p1))res.pb(l.p1);
  if(in(c,l.p2))res.pb(l.p2);
  if(ccw(l.p1,l.p2,pp.f)==0)res.pb(pp.f);
  if(ccw(l.p1,l.p2,pp.s)==0)res.pb(pp.s);
  return res;
}

Point rotate(Point base,Point a,double r){
  Point b=a-base;
  a.x=b.x*cos((r/180.0)*pi)-b.y*sin((r/180.0)*pi);
  a.y=b.x*sin((r/180.0)*pi)+b.y*cos((r/180.0)*pi);
  a=a+base;
  return a;
}

double getAngle(Vector a,Vector b){
  double tmp=dot(a,b)/(abs(a)*abs(b));
  if(tmp<-1.0)tmp=-1.0;
  if(1.0<tmp)tmp=1.0;
  double r=acos(tmp)*180.0/pi;
  if(cross(a,b)<-eps)r=360.0-r;
  return r;
}

int n;
double l,r;
Polygon p;

pair<double,Point> find(Point M,Vector v){
  Circle c(M,abs(v));
  pair<double,Point> ev(inf,Point(inf,inf));
  FOR(i,0,n){
    Line L(p[i],p[(i+1)%n]);
    if(!intersect(c,L))continue;
    vector<Point> pp = getCrossPoint(c,L);
    FOR(j,0,pp.size()){
      double r1=360.0-getAngle(v,pp[j]-M);
      if(r1!=ev.f ? r1<ev.f : 
                    abs(ev.s-M)<abs(pp[j]-M))ev=mp(r1,pp[j]);
    }
  }
  return ev;
}

bool check(Point A,Point M){
  Vector v1 = M-A;
  FOR(i,0,n){
    Line L(p[i],p[(i+1)%n]);
    Vector v2 = L.p1-L.p2;
    if(!(A==p[i]) && !(M==p[i]) && 
      ccw(A,M,L.p1)==0 && ccw(A,M,L.p2)==1)return false;
    if(ccw(L.p1,L.p2,A)==0){
      double r1=getAngle(v1,v2);
      if(r1>180.0)r1=360-r1;
      if(r1-90.0<-eps)return false;
    }
  }
  return true;
}

Point solve(){
  r*=360.0;
  Point A(0,0),B(0,l),M(0,0);
  while(1){
    pair<double,Point> ev(inf,Point(inf,inf));
    if(!(A==M)){
      if(!check(A,M))break;
      pair<double,Point> res=find(M,A-M);
      if(res.f!=ev.f ? res.f<ev.f : 
                    abs(ev.s-M)<abs(res.s-M))ev=res;
    }
    if(!(B==M)){
      if(!check(B,M))break;
      pair<double,Point> res=find(M,B-M);  
      if(res.f!=ev.f ? res.f<ev.f : 
                    abs(ev.s-M)<abs(res.s-M))ev=res;
    }
    if(r-ev.f<-eps)ev.f=r;
    Point nA=rotate(M,A,360.0-ev.f);
    Point nB=rotate(M,B,360.0-ev.f);
    A=nA;
    B=nB;
    M=ev.s;
    r-=ev.f;
    if(r<eps)break;
  }
  return A;
}

int main()
{
  while(1){
    cin>>l>>r>>n;
    if(n==0)break;
    p.clear();
    FOR(i,0,n){
      int x,y;
      cin>>x>>y;
      p.pb(Point(x,y));
    }
    Point ans = solve();
    printf("%.10f %.10f\n",ans.x,ans.y);
  }
  return 0;
}