1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 100000+10
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 #define mod 1000000007
23 #define sqr(x) (x)*(x)
24 using namespace std;
25 inline ll read()
26 {
27 ll x=0,f=1;char ch=getchar();
28 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
29 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}
30 return x*f;
31 }
32 int n,cs,lim,ans,mx,id,p[4*maxn];
33 struct rec{ll x,y;}b[maxn];
34 struct rec2
35 {
36 bool type;//表示该点的属性,是角还是边
37 ll x;
38 friend bool operator ==(rec2 a,rec2 b)
39 {
40 return a.type==b.type&&a.x==b.x;
41 }
42 }a[4*maxn];
43 inline ll dist(rec a,rec b)//距离的平方
44 {
45 return sqr(a.x-b.x)+sqr(a.y-b.y);
46 }
47 inline ll cross(rec a,rec b,rec c)//叉积
48 {
49 return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
50 }
51 int main()
52 {
53 freopen("input.txt","r",stdin);
54 freopen("output.txt","w",stdout);
55 cs=read();
56 while(cs--)
57 {
58 n=read();
59 for0(i,n-1)b[i].x=read(),b[i].y=read();
60 for0(i,n-1)
61 {
62 a[i<<1|1].type=1;
63 a[i<<1|1].x=dist(b[i],b[(i+1)%n]);
64 }
65 for0(i,n-1)
66 {
67 a[i<<1].type=0;
68 a[i<<1].x=cross(b[i],b[(i-1+n)%n],b[(i+1)%n]);
69 }
70 lim=n<<1;
71 for0(i,lim-1)a[i+lim]=a[i];//将原串赋值一遍
72 lim<<=1;
73 mx=id=0;memset(p,0,sizeof(p));
74 for0(i,lim-1)
75 {
76 if(mx>i)p[i]=min(p[2*id-i],mx-i);
77 for(;i-p[i]>=0,i+p[i]<lim,a[i-p[i]]==a[i+p[i]];p[i]++)
78 if(i+p[i]>mx){mx=i+p[i];id=i;}
79 }//manacher
80 ans=0;
81 for0(i,lim-1)if(p[i]-1>=n)ans++;//每条对称轴有两个顶点
82 printf("%d\n",ans>>1);
83 }
84 return 0;
85 }