#pragma GCC optimize("O2")
#include <cstdio>
char buf[20000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
bool flag = false;
while(*++ptr < ‘0‘ || *ptr > ‘9‘) if(*ptr == ‘-‘) flag = true;
while(*ptr <= ‘9‘ && *ptr >= ‘0‘) n = (n << 1) + (n << 3) + (*ptr++ & 15);
return flag ? -n : n;
}
template <typename _Tp>
inline _Tp min_(const _Tp &a, const _Tp &b){
return a < b ? a : b;
}
typedef long long ll;
const int maxn = 100000 + 10;
struct Poi{
ll x, y;
Poi(){}
Poi(ll _x, ll _y): x(_x), y(_y){}
Poi operator - (const Poi &a){
return Poi(x - a.x, y - a.y);
}
}p[maxn];
inline ll sqr(const ll &x){
return x * x;
}
inline ll dis(const Poi &a, const Poi &b){
return sqr(a.x - b.x) + sqr(a.y - b.y);
}
inline ll cross(const Poi &a, const Poi &b){
return a.x * b.y - a.y * b.x;
}
int n;
ll s[maxn * 3];
int r[maxn * 3];
void work(){
n = readint();
for(int i = 1; i <= n; i++){
p[i].x = readint();
p[i].y = readint();
}
p[0] = p[n];
p[n + 1] = p[1];
for(int i = 1; i <= n; i++){
s[i * 2 - 1] = cross(p[i - 1] - p[i], p[i + 1] - p[i]);
s[i * 2] = dis(p[i], p[i + 1]);
}
int len = n + n;
for(int i = 1; i <= n; i++)
s[i + len] = s[i];
len = len + n;
int mx = 0, id = 0, ans = 0;
for(int i = 1; i <= len; i++){
if(mx > i) r[i] = min_(r[2 * id - i], mx - i);
else r[i] = 1;
while(i - r[i] > 0 && i + r[i] <= len && s[i - r[i]] == s[i + r[i]]) r[i]++;
if(r[i] + i > mx){
mx = r[i] + i;
id = i;
}
if(r[i] > n) ans++;
}
printf("%d\n", ans);
}
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
int T = readint();
while(T--) work();
return 0;
}