#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a[n + 123];
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 2; i <= n; i++)
a[i] += a[i - 1];
int mn = 0, mx = 0, ans = 0;
for (int i = 1; i * i <= n; i++)
{
if (n % i == 0)
{
int l = i;
for (int j = l; j <= n; j += l)
{
int s = a[j] - a[j - l];
cout << 1 << " " << s << endl;
mn = min(mn, s);
mx = max(mx, s);
}
}
}
ans = mx - mn;
cout << ans << endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCB0OwogICAgY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKQogICAgewogICAgICAgIGludCBuOwogICAgICAgIGNpbiA+PiBuOwogICAgICAgIGludCBhW24gKyAxMjNdOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKICAgICAgICAgICAgY2luID4+IGFbaV07CgogICAgICAgIGZvciAoaW50IGkgPSAyOyBpIDw9IG47IGkrKykKICAgICAgICAgICAgYVtpXSArPSBhW2kgLSAxXTsKCiAgICAgICAgaW50IG1uID0gMCwgbXggPSAwLCBhbnMgPSAwOwogICAgICAgIGZvciAoaW50IGkgPSAxOyBpICogaSA8PSBuOyBpKyspCiAgICAgICAgewogICAgICAgICAgICBpZiAobiAlIGkgPT0gMCkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaW50IGwgPSBpOwogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IGw7IGogPD0gbjsgaiArPSBsKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGludCBzID0gYVtqXSAtIGFbaiAtIGxdOwogICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgMSA8PCAiICIgPDwgcyA8PCBlbmRsOwogICAgICAgICAgICAgICAgICAgIG1uID0gbWluKG1uLCBzKTsKICAgICAgICAgICAgICAgICAgICBteCA9IG1heChteCwgcyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgYW5zID0gbXggLSBtbjsKICAgICAgICBjb3V0IDw8IGFucyA8PCBlbmRsOwogICAgfQoKICAgIHJldHVybiAwOwp9
NQoyCjEgMgo2CjEwIDIgMyA2IDEgMwo0CjEwMDAwMDAwMDAgMTAwMDAwMDAwMCAxMDAwMDAwMDAwIDEwMDAwMDAwMDAKMTUKNjA5NzggODIyNjUgNzg5NjEgNTY3MDggMzk4NDYgMzEwNzEgNDkxMyA0NzY5IDI5MDkyIDkxMzQ4IDY0MTE5IDcyNDIxIDk4NDA1IDIyMiAxNDI5NAo4CjE5OTU3IDY5OTEzIDM3NTMxIDk2OTkxIDU3ODM4IDIxMDA4IDE0MjA3IDE5MTk4Cg==
5
2
1 2
6
10 2 3 6 1 3
4
1000000000 1000000000 1000000000 1000000000
15
60978 82265 78961 56708 39846 31071 4913 4769 29092 91348 64119 72421 98405 222 14294
8
19957 69913 37531 96991 57838 21008 14207 19198