1. JAVA, Peter Schnitzler

/* Problem : 10020
* Author : Peter Schnitzler
* Status : AC
* Runtime : 2.860
*/

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.StringTokenizer;


public class Main
{

public static void main(String[] args) throws Exception
{
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));


int rounds = Integer.parseInt(read.readLine().trim());

for (int r = 0; r < rounds;r++)
{
read.readLine();

final int max = Integer.parseInt(read.readLine().trim());
//the length of the section that has to be covered
LinkedList<double[]> input = new LinkedList<double[]>();
//saves the input for the calculation
LinkedList<String> stringInputs = new LinkedList<String>();
//saves the input for the output

while (true)
{
String line = read.readLine();
StringTokenizer tok = new StringTokenizer(line);

double i1 = Double.parseDouble(tok.nextToken());
double i2 = Double.parseDouble(tok.nextToken());


if (i1 != 0 || i2 != 0)
{

//sorting input
if (i1 > i2)
{
double temp = i1;
i1 = 12;
i2 = temp;
}


//input must matter
if (i1 != i2)
{
if (i2 > 0 && i1 < max)
{
double inArray [] = {i1 , i2};

input.add(inArray);
stringInputs.add(line);
}
}
}

//end of input
else
{
break;
}
}


//no good input
if (input.isEmpty())
{
System.out.print("0\n\n");
continue;
}


double position = 0; //the point currently reached
int resultCount = 0; //the number of elements in the solution
boolean foundSomething = false; //recognize that there is no solution
LinkedList<String> optimalInputs = new LinkedList<String>();


while (position < max)
{
foundSomething = false;
Iterator<double[]> iter = input.iterator();
double best = position;
int posOfBest = 0; //the position of the best input in input

//looking for the interval that reaches the farest from the current position reached
for (int c = 0; iter.hasNext(); c++)
{
double current[] = iter.next();

if (current[0] <= (position + 0.000001) && (current[1]) > best)
{
best = current[1];
posOfBest = c;

foundSomething = true;
}
}


if (foundSomething)
{
resultCount++;
position = best;
optimalInputs.add(stringInputs.get(posOfBest));
}
else
{
break;
}
}


//output
if (foundSomething)
{
StringBuilder sB = new StringBuilder();
sB.append(resultCount + "\n");

for (String s : optimalInputs)
{
sB.append(s + "\n");
}
sB.append("\n");

System.out.print(sB.toString());
}
else
{
System.out.print("0\n\n");
}
}
}

}