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 JAVA):

Solution:
import java.awt.geom.*;
import java.util.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	Main(){
		new AOJ1212();
	}
	
	class AOJ1212{
		AOJ1212(){
			while(true){
				N=sc.nextInt();
				if(N<0)	break;
				solve();
			}
		}
		int N;
		final double EPS=1.0e-4;
		void solve(){
			Line2D[] mirrors = new Line2D[N];
			for(int i=0; i<N; ++i){
				String d = sc.next();
				int x=sc.nextInt(), y=sc.nextInt();
				mirrors[i]=new Line2D.Double(x, y, x+(d.equals("x")? 1: 0), y+(d.equals("y")? 1: 0));
			}
			Line2D[] walls = new Line2D[4];
			walls[0]=new Line2D.Double(0,0,8,0);
			walls[1]=new Line2D.Double(8,0,8,8);
			walls[2]=new Line2D.Double(8,8,0,8);
			walls[3]=new Line2D.Double(0,8,0,0);
			
			Point2D start = new Point2D.Double(0.75,0.25),
					ans=start;
			Line2D l=new Line2D.Double(0.75, 0.25, 0.75+100, 0.25+100);
			
			Point2D[] vv= {new Point2D.Double(100,100), new Point2D.Double(-100,100),
						new Point2D.Double(100,-100), new Point2D.Double(-100,-100)};
			
			int cnt=0,v=0;
			boolean fin=false;
			while(!fin){
				
				boolean bs = cnt>0 && l.ptSegDist(start)<EPS;
				++cnt;
				
				double dis = 100;
				Point2D p=null;
				int idx=-1;
				for(int i=0; i<N; ++i){
					if(l.intersectsLine(mirrors[i])){
						Point2D b = intersectionPoint(l, mirrors[i]);
						double a = b.distance(l.getP1());
						if(a < dis && a>EPS){
							dis = a;
							p=b;
							idx=i;
						}
					}
				}
				
//				System.out.println("P:"+p+" L:"+l.getP1()+","+l.getP2());
				
				if(p==null){
					if(bs)	break;
					for(int i=0; i<4; ++i){
						if(l.intersectsLine(walls[i])){
							Point2D tmp = intersectionPoint(l, walls[i]);
							if(tmp.distance(l.getP1()) > EPS){
								ans=tmp;
								fin=true;
								break;
							}
						}
					}
				}else{
					if(bs){
						double tmp = start.distance(l.getP1());
						if(tmp < dis)	break;
					}
					
					if(mirrors[idx].getX1()==mirrors[idx].getX2()){
						v = v^1;
					}else{
						v = v^2;
					}
					double px = p.getX()*100+EPS, py = p.getY()*100+EPS;
					p = new Point2D.Double((int)px/100.0, (int)py/100.0);
					l=new Line2D.Double(p, sum(p, vv[v]));
					
				}
			}
			
			System.out.println((int)(ans.getX()*100+EPS) +" "+ (int)(ans.getY()*100+EPS));
			
		}
		Point2D intersectionPoint(Line2D l1,Line2D l2){
			return intersectionPoint(l1.getP1(), l1.getP2(), l2.getP1(), l2.getP2());
		}
		Point2D intersectionPoint(Point2D a1,Point2D a2,Point2D b1,Point2D b2){
			Point2D a=diff(a2,a1),
					b=diff(b2,b1);
			return sum(a1, mul(cross(b, diff(b1,a1))/cross(b,a), a));
		}
		Point2D sum(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()+p2.getX(), p1.getY()+p2.getY());
		}
		Point2D diff(Point2D p1,Point2D p2){
			return new Point2D.Double(p1.getX()-p2.getX(), p1.getY()-p2.getY());
		}
		Point2D mul(double n,Point2D p1){
			return new Point2D.Double(p1.getX()*n, p1.getY()*n);
		}
		double cross(Point2D p1,Point2D p2){
			return p1.getX()*p2.getY() - p2.getX()*p1.getY();
		}
	}
}