package com.company;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.*;
/**
* meng3.wei 2020.05.08
(输入)
3
3
1 1
2 2
3 3
3
1 1
2 2
3 1
4
1 1
3 1
2 4
4 4
(输出)
#1 2
#2 -1
#3 1
*/
public class 跳跃路径 {
static int T;
static int N;
static Point[] points;
static int[] result;
static int[] pCount;//存储开始节点到这个节点的路径个数
static int MAX=1000000007;
static boolean logger=false;
public static void main(String[] args)throws Exception {
//System.setIn(new FileInputStream("D:\\sw_case\\35\\test_input.txt"));
//System.setIn(new FileInputStream("D:\\sw_case\\35\\sample_input_2.txt"));
//System.setIn(new FileInputStream("D:\\sw_case\\35\\sample_input.txt"));
System.setIn(new FileInputStream("D:\\sw_case\\35\\eval_input.txt"));
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
T=Integer.parseInt(reader.readLine());
result=new int[T];
for (int i = 0; i < T; i++) {
N=Integer.parseInt(reader.readLine());
pCount=new int[N];
points=new Point[N];
String str[];
for (int j = 0; j <N ; j++) {
str=reader.readLine().split(" ");
points[j]=new Point(Integer.parseInt(str[0]),Integer.parseInt(str[1]));
}
Arrays.sort(points,1,N-1);//要把第一个节点和最后一个节点排除掉
if(points[N-1].x <=points[0].x || points[N-1].y <=points[0].y){
result[i]=-1;
continue;
}
pCount[0]=1;
for (int j = 1; j < points.length; j++) {//到达当前节点的路径个数=sum(每个可以达到当前节点的路径个数)
for (int k = 0; k < j; k++) {
if(points[j].x>points[k].x
&&points[j].y>points[k].y
){//k是起始节点 j是结束节点
pCount[j]=(pCount[j]+pCount[k])%MAX;
}
}
}
result[i]=pCount[N-1];
}
for (int i = 0; i < T; i++) {
System.out.printf("#%d %d\n",(i+1),result[i]);
}
reader.close();
}
}
class Point implements Comparable<Point>{
public int x;
public int y;
public Point(int x,int y){
this.x=x;
this.y=y;
}
@Override
public int compareTo(Point o2) {
if(this.x==o2.x){
return this.y-o2.y;
}else{
return this.x-o2.x;
}
}
}