import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0;i< t;i++) {
int q = 0;
int z = 0;
int m = sc.nextInt();
if(m==0) {
System.out.println(3);
continue;
}
Map<String,Integer> r1 =new HashMap<>();
Map<String,Integer> r2 =new HashMap<>();
for(int j = 0; j < m;j++) {
int y = sc.nextInt();
int x = sc.nextInt();
if(((x==-1&&y==1)||(x==1&&y==1))) {
q = 1;
z++;
}
if(x>0) r1.put(x+" "+y, 1);
else if(x<0) r2.put(x+" "+y, 1);
else {
r1.put(x+" "+y, 1);
r2.put(x+" "+y, 1);
}
}
System.out.println(Math.min(cnt(r1)+cnt(r2), 3-z));
}
}
public static int cnt(Map<String,Integer> map) {
if(map.isEmpty()) return 2;
for(String s:map.keySet()) {
String[] arr = s.split(" ");
int x = Integer.parseInt(arr[0]);
int y = Integer.parseInt(arr[1]);
if(y==1) {
if(map.get((x-1)+" "+2)!=null||map.get((x+1)+" "+2)!=null||map.get(x+" "+2)!=null) return 0;
}else {
if(map.get((x-1)+" "+1)!=null||map.get((x+1)+" "+1)!=null||map.get(x+" "+1)!=null) return 0;
}
}
return 1;
}
}
全部评论
(0) 回帖