1. 

/**
* FWP, Ausgew¤hlte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11626 - Convex Hull
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2673
*
* @author Evgeni Pavlidis
* @version 1.0, 06/02/2010
*
* Method : Comp. Geometry - (Graham Scan)
* Status : Accepted
* Runtime: 0.596
*/

/* Sorting of points relative to pivot by angle
Java may be too slow for this problem,
because of large input/output */

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

#define MAX 100000
int X = 0;
int Y = 1;


int point[MAX][2];
int points;

int startPoint[2];

double angle[MAX];



double getAngle(int a[], int b[])
{
return atan((double)(a[Y]-b[Y])/(double)(a[X]-b[X]));
}

long dist(int a[], int b[])
{
long tmp, result;

tmp = a[X] - b[X];
result = tmp*tmp;
tmp = a[Y] - b[Y];
result += tmp*tmp;

return result;
}


int compare(const void* x, const void* y)
{
int* a = (int*)x;
int* b = (int*)y;

double thisAngle = getAngle(a, startPoint);
double otherAngle = getAngle(b, startPoint);


long thisDist = dist(a, startPoint);
long otherDist = dist(b, startPoint);


if(thisAngle != thisAngle)
return -1;
if(otherAngle != otherAngle)
return 1;

if(thisAngle < otherAngle)
return -1;
if(thisAngle > otherAngle)
return 1;

if(thisDist < otherDist)
return 1;
if(thisDist > otherDist)
return -1;

return 0;
}



int findMin()
{
int minX = point[0][X];
int minY = point[0][Y];
int save = 0;

for(int p = 0; p < points; p++)
if(point[p][X] < point[save][X] || (point[p][X] == point[save][X] && point[p][Y] < point[save][Y]))
save = p;

return save;
}




int main()
{

int testCases;
cin >> testCases;

int n, x, y;
char c;

for(int t = 1; t <= testCases; t++)
{
cin >> n;
points = 0;

for(int i = 0; i < n; i++)
{
cin >> x;
cin >> y;
cin >> c;
if(c == 'Y')
{
point[points][X] = x;
point[points][Y] = y;
points++;
}
}

int min = findMin();
startPoint[X] = point[min][X];
startPoint[Y] = point[min][Y];

qsort(point,points,sizeof(int)*2, compare);

cout << points << endl;
for(int i = 0; i < points; i++)
cout << point[i][X] << " " << point[i][Y] << endl;
}

}