Problem: A rich man has a square room with mirrors for security or just for fun. Each side of the room is eight meters wide. The floor, the ceiling and the walls are not special; however, the room can be equipped with a lot of mirrors on the walls or as vertical partitions.

Every mirror is one meter wide, as tall as the wall, double-side, perfectly reflective, and ultimately thin.

Poles to fix mirrors are located at the corners of the room, on the walls and inside the room. Their locations are the 81 lattice points at intervals of one meter. A mirror can be fixed between two poles which are one meter distant from each other. If we use the sign "+" to represent a pole, the overview of the room can be illustrated as follows.

<image>

Let us denote a location on the floor by (x,y) in a rectangular coordinate system. For example, the rectangular coordinates of the four corners of the room are (0,0), (8,0), (0,8) and (8,8), respectively. The location (x,y) is in the room if and only if the conditions 0 ≤ x ≤ 8 and 0 ≤ y ≤ 8 are satisfied. If i and j are integers satisfying the conditions 0 ≤ i ≤ 8 and 0 ≤ j ≤ 8, we can denote by (i,j) the locations of poles.

One day a thief intruded into this room possibly by breaking the ceiling. He stood at (0.75,0.25) and looked almost toward the center of the room. Precisely speaking, he looked toward the point (1, 0.5) of the same height as his eyes. So what did he see in the center of his sight? He would have seen one of the walls or himself as follows.

* If there existed no mirror, he saw the wall at (8, 7.5)
* If there existed one mirror between two poles at (8, 7) and (8, 8), he saw the wall at (7.5, 8). (Let us denote the line between these two poles by (8, 7)-(8, 8).)
* If there were four mirrors on (8, 7)-(8, 8), (7, 8)-(8, 8), (0, 0)-(0, 1) and (0, 0)-(1, 0), he saw himself at (0.75, 0.25).
* If there were four mirrors on (2, 1)-(2, 2), (1, 2)-(2, 2), (0, 0)-(0, 1) and (0, 0)-(1, 0), he saw himself at (0.75, 0.25)



Your job is to write a program that reports the location at which the thief saw one of the walls or himself with the given mirror arrangements.



Input

The input contains multiple data sets, each representing how to equip the room with mirrors. A data set is given in the following format.


n
d1 i1 j1
d2 i2 j2
. . .
dn in jn


The first integer n is the number of mirrors, such that 0 ≤ n ≤ 144. The way the k-th (1 ≤ k ≤ n) mirror is fixed is given by dk and (ik,jk). dk is either 'x' or 'y', which gives the direction of the mirror. If dk is 'x', the mirror is fixed on (ik, jk)-(ik + 1, jk). If dk is 'y', the mirror is fixed on (ik,jk) (ik,jk + 1). The end of the input is indicated by a negative integer.

Output

For each data set, your program should output the location (x,y) at which the thief saw one of the walls or himself. The location should be reported in a line containing two integers which are separated by a single space and respectively represent x and y in centimeter as the unit of length. No extra lines nor spaces are allowed.

Example

Input

0
1
y 8 7
4
y 8 7
x 7 8
y 0 0
x 0 0
4
y 2 1
x 1 2
y 0 0
x 0 0
-1


Output

800 750
750 800
75 25
75 25

Solution (in CPP):

Solution:
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
int is_point_on_line(P a, P b, P c) {
  return EQ( cross(b-a, c-a), 0.0 );
}
int is_intersected_ls(P a1, P a2, P b1, P b2) {
    if(abs(cross(a2-a1,b2-b1)) < EPS){
        return 0;
    }
    return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
        ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}
P intersection_ls(P a1, P a2, P b1, P b2) {
  P b = b2-b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);

  return a1 + (a2-a1) * t;
}


int main(){
    int n;
    vector<pair<P,P> > wall;
    wall.push_back(make_pair(P(0,0),P(0,8)));
    wall.push_back(make_pair(P(0,0),P(8,0)));
    wall.push_back(make_pair(P(8,8),P(0,8)));
    wall.push_back(make_pair(P(8,8),P(8,0)));
    while(cin>>n&&n>=0){
        vector<pair<P,P> > mirror;
        for(int i = 0; i < n; i++){
            char a;
            int x,y;
            cin>>a>>x>>y;
            if(a=='x')
                mirror.push_back(make_pair(P(x,y),P(x+1,y)));
            else
                mirror.push_back(make_pair(P(x,y),P(x,y+1)));
        }
        const P sp=P(0.75,0.25);
        P ang=P(1,1);
        P cp=sp;
        bool first=true;
        int prvMatchMirror=-1;
        while(1){
            double minMirrorDist=10000000.0;
            P nearMirror=P(-1,-1);
            bool isHor=false;
            int p=-1;
            for(int i = 0; i < n; i++){
                P tmp=ang;
                tmp*=100;
                if(is_intersected_ls(cp,cp+tmp,mirror[i].first,mirror[i].second)
                    &&prvMatchMirror!=i){
                    P crossPoint=intersection_ls(cp,cp+tmp,mirror[i].first,mirror[i].second);
                    double d=abs(crossPoint-cp);
                    if(minMirrorDist>d){
                        minMirrorDist=d;
                        nearMirror=crossPoint;
                        isHor=(EQ(mirror[i].first.imag()-mirror[i].second.imag(),0));
                        p=i;
                    }
                }
            }
            prvMatchMirror=p;
            if(!first&&is_point_on_line(cp,cp+ang,sp)){
                double d=abs(cp-sp);
                if(d<minMirrorDist){
                    printf("%d %d\n",(int)(EPS+100*sp.real()),(int)(EPS+100*sp.imag()));
                    break;
                }
            }
            first=false;
            if(EQ(nearMirror.real(),-1)){
                for(int i = 0; i < wall.size(); i++){
                    P tmp=ang;
                    tmp*=100;
                    if(is_intersected_ls(cp,cp+tmp,wall[i].first,wall[i].second)){
                        P crossPoint=intersection_ls(cp,cp+tmp,wall[i].first,wall[i].second);
                        if(EQV(crossPoint,cp))
                            continue;
                        cp=crossPoint;
                        printf("%d %d\n",(int)(100*cp.real()+EPS),(int)(100*cp.imag()+EPS));
                        break;
                    }
                }
                break;
            }
            else{
                cp=nearMirror;
                if(isHor)
                    ang=P(ang.real(),-ang.imag());
                else
                    ang=P(-ang.real(),ang.imag());
            }
        }
    }
    return 0;
}