1 #include <bits/stdc++.h>
2
3 template <class Int>
4 inline Int sqr(const Int &num) {
5 return num * num;
6 }
7
8 template <class Int>
9 inline Int min(const Int &a, const Int &b) {
10 return a < b ? a : b;
11 }
12
13 const int maxn = 800005;
14
15 int n;
16 int cas;
17 int len;
18 int x[maxn];
19 int y[maxn];
20 int s[maxn];
21 int r[maxn];
22
23 inline int calc1(int mid) {
24 int left = (mid - 1 + n) % n;
25 int right = (mid + 1 + n) % n;
26 return
27 (x[left] - x[mid]) * (y[mid] - y[right])
28 - (y[left] - y[mid]) * (x[mid] - x[right]);
29 }
30
31 inline int calc2(int left) {
32 int right = (left + 1 + n) % n;
33 return
34 sqr(x[left] - x[right])
35 + sqr(y[left] - y[right]);
36 }
37
38 signed main(void) {
39 scanf("%d", &cas);
40 while (cas--) {
41 scanf("%d", &n);
42 for (int i = 0; i < n; ++i)
43 scanf("%d%d", x + i, y + i);
44 memset(s, 0, sizeof(s));
45 for (int i = 0; i < n; ++i) {
46 s[i << 1] = calc1(i);
47 s[i << 1 | 1] = calc2(i);
48 }
49 len = n << 1;
50 for (int i = 0; i < n; ++i)
51 s[len + i] = s[i];
52 len = n << 2;
53 int maxi = 0, id = 0, answer = 0;
54 for (int i = 0; i < len; ++i) {
55 if (maxi > i)
56 r[i] = min(r[2*id - i], maxi - i);
57 else
58 r[i] = 1;
59 while (i - r[i] >= 0 && i + r[i] <= len
60 && s[i - r[i]] == s[i + r[i]])++r[i];
61 if (maxi < i + r[i])
62 maxi = i + r[i], id = i;
63 if (r[i] > n)++answer;
64 }
65 printf("%d\n", answer);
66 }
67 }