#include <bits/stdc++.h>
using namespace std;
struct _complex {
double x, y;
_complex () : x(0.0), y(0.0) {}
_complex (double _x, double _y) : x(_x), y(_y) {}
const _complex operator + (const _complex &z) {
return _complex(x + z.x, y + z.y);
}
const _complex operator - (const _complex &z) {
return _complex(x - z.x, y - z.y);
}
const _complex operator * (const _complex &z) {
return _complex(x * z.x - y * z.y, x * z.y + y * z.x);
}
};
const int LG = 17;
const int B = 2000;
const int N = 200005;
const int L = 1 << 17;
const double PI = acos(-1);
int t, n;
_complex f[N];
int a[N], rev[N];
int pref[N], active[N];
_complex power[2][20][N];
void process (void) {
for (int i = 0; i < L; ++i) {
rev[i] = 0;
for (int j = 0; j < LG; ++j) {
if (i & 1 << j) {
rev[i] |= 1 << (LG - 1 - j);
}
}
}
for (int dir = 0; dir < 2; ++dir) {
for (int i = 1; i <= LG; ++i) {
int l = 1 << i;
double theta = 2 * PI / l * (dir ? -1 : 1);
_complex base(cos(theta), sin(theta));
power[dir][i][0] = _complex(1, 0);
for (int j = 1; j < (l >> 1); ++j) {
power[dir][i][j] = base * power[dir][i][j - 1];
}
}
}
}
void fft (int dir) {
for (int i = 0; i < L; ++i) {
if (i < rev[i]) {
swap(f[i], f[rev[i]]);
}
}
for (int i = 1; i <= LG; ++i) {
int l = 1 << i;
for (int j = 0; j < L; j += l) {
_complex z, *w = power[dir][i];
_complex *u = f + j, *v = f + j + (l >> 1);
_complex *lim = f + j + (l >> 1);
while (u != lim) {
z = *v * *w;
*v = *u - z;
*u = *u + z;
++u, ++v, ++w;
}
}
}
if (dir == 1) {
for (int i = 0; i < L; ++i) {
f[i].x /= L;
f[i].y /= L;
}
}
}
void square (void) {
for (int j = 0; j < L; ++j) {
f[j] = _complex(pref[j], 0);
}
fft(0);
for (int j = 0; j < L; ++j) {
f[j] = f[j] * f[j];
}
fft(1);
}
int main() {
process();
scanf("%d", &t);
while (t--) {
memset(pref, 0, sizeof pref);
memset(active, 0, sizeof active);
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
long long ans = 0;
for (int i = 1; i <= n; i += B) {
int l = i, r = min(n, i + B - 1);
long long inside = 0;
for (int j = l; j <= r; ++j) {
for (int k = j + 1; k <= r; ++k) {
if (a[k] > a[j]) {
inside += (long long) active[a[k] - a[j]];
inside += (long long) pref[a[k] - a[j]];
}
}
++active[a[j]];
}
ans += inside;
if (i > 1) {
square();
long long outside = 0;
for (int j = l; j <= r; ++j) {
long long add = floor(f[a[j]].x + 0.5);
if (!(a[j] & 1)) add -= pref[a[j] >> 1];
outside += (add >> 1);
}
ans += outside;
}
for (int j = l; j <= r; ++j) {
++pref[a[j]];
--active[a[j]];
}
}
printf("%lld\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IF9jb21wbGV4IHsKICBkb3VibGUgeCwgeTsKICAKICBfY29tcGxleCAoKSA6IHgoMC4wKSwgeSgwLjApIHt9CiAgX2NvbXBsZXggKGRvdWJsZSBfeCwgZG91YmxlIF95KSA6IHgoX3gpLCB5KF95KSB7fQogIAogIGNvbnN0IF9jb21wbGV4IG9wZXJhdG9yICsgKGNvbnN0IF9jb21wbGV4ICZ6KSB7CiAgICByZXR1cm4gX2NvbXBsZXgoeCArIHoueCwgeSArIHoueSk7CiAgfQogIAogIGNvbnN0IF9jb21wbGV4IG9wZXJhdG9yIC0gKGNvbnN0IF9jb21wbGV4ICZ6KSB7CiAgICByZXR1cm4gX2NvbXBsZXgoeCAtIHoueCwgeSAtIHoueSk7CiAgfQogIAogIGNvbnN0IF9jb21wbGV4IG9wZXJhdG9yICogKGNvbnN0IF9jb21wbGV4ICZ6KSB7CiAgICByZXR1cm4gX2NvbXBsZXgoeCAqIHoueCAtIHkgKiB6LnksIHggKiB6LnkgKyB5ICogei54KTsKICB9Cn07Cgpjb25zdCBpbnQgTEcgPSAxNzsKY29uc3QgaW50IEIgPSAyMDAwOwpjb25zdCBpbnQgTiA9IDIwMDAwNTsKY29uc3QgaW50IEwgPSAxIDw8IDE3Owpjb25zdCBkb3VibGUgUEkgPSBhY29zKC0xKTsKCmludCB0LCBuOwpfY29tcGxleCBmW05dOwppbnQgYVtOXSwgcmV2W05dOwppbnQgcHJlZltOXSwgYWN0aXZlW05dOwpfY29tcGxleCBwb3dlclsyXVsyMF1bTl07Cgp2b2lkIHByb2Nlc3MgKHZvaWQpIHsKICBmb3IgKGludCBpID0gMDsgaSA8IEw7ICsraSkgewogICAgcmV2W2ldID0gMDsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgTEc7ICsraikgewogICAgICBpZiAoaSAmIDEgPDwgaikgewogICAgICAgIHJldltpXSB8PSAxIDw8IChMRyAtIDEgLSBqKTsKICAgICAgfQogICAgfQogIH0KCiAgZm9yIChpbnQgZGlyID0gMDsgZGlyIDwgMjsgKytkaXIpIHsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IExHOyArK2kpIHsKICAgICAgaW50IGwgPSAxIDw8IGk7CiAgICAgIGRvdWJsZSB0aGV0YSA9IDIgKiBQSSAvIGwgKiAoZGlyID8gLTEgOiAxKTsKICAgICAgX2NvbXBsZXggYmFzZShjb3ModGhldGEpLCBzaW4odGhldGEpKTsKICAgICAgcG93ZXJbZGlyXVtpXVswXSA9IF9jb21wbGV4KDEsIDApOwogICAgICBmb3IgKGludCBqID0gMTsgaiA8IChsID4+IDEpOyArK2opIHsKICAgICAgICBwb3dlcltkaXJdW2ldW2pdID0gYmFzZSAqIHBvd2VyW2Rpcl1baV1baiAtIDFdOwogICAgICB9CiAgICB9CiAgfQp9Cgp2b2lkIGZmdCAoaW50IGRpcikgewogIGZvciAoaW50IGkgPSAwOyBpIDwgTDsgKytpKSB7CiAgICBpZiAoaSA8IHJldltpXSkgewogICAgICBzd2FwKGZbaV0sIGZbcmV2W2ldXSk7CiAgICB9CiAgfQoKICBmb3IgKGludCBpID0gMTsgaSA8PSBMRzsgKytpKSB7CiAgICBpbnQgbCA9IDEgPDwgaTsKICAgIGZvciAoaW50IGogPSAwOyBqIDwgTDsgaiArPSBsKSB7CiAgICAgIF9jb21wbGV4IHosICp3ID0gcG93ZXJbZGlyXVtpXTsKICAgICAgX2NvbXBsZXggKnUgPSBmICsgaiwgKnYgPSBmICsgaiArIChsID4+IDEpOwogICAgICBfY29tcGxleCAqbGltID0gZiArIGogKyAobCA+PiAxKTsKICAgICAgd2hpbGUgKHUgIT0gbGltKSB7CiAgICAgICAgeiA9ICp2ICogKnc7CiAgICAgICAgKnYgPSAqdSAtIHo7CiAgICAgICAgKnUgPSAqdSArIHo7CiAgICAgICAgKyt1LCArK3YsICsrdzsKICAgICAgfQogICAgfQogIH0KCiAgaWYgKGRpciA9PSAxKSB7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IEw7ICsraSkgewogICAgICBmW2ldLnggLz0gTDsKICAgICAgZltpXS55IC89IEw7CiAgICB9CiAgfQp9Cgp2b2lkIHNxdWFyZSAodm9pZCkgewogIGZvciAoaW50IGogPSAwOyBqIDwgTDsgKytqKSB7CiAgICBmW2pdID0gX2NvbXBsZXgocHJlZltqXSwgMCk7IAogIH0KICBmZnQoMCk7CiAgZm9yIChpbnQgaiA9IDA7IGogPCBMOyArK2opIHsKICAgIGZbal0gPSBmW2pdICogZltqXTsKICB9CiAgZmZ0KDEpOwp9CgppbnQgbWFpbigpIHsKICBwcm9jZXNzKCk7CiAgCiAgc2NhbmYoIiVkIiwgJnQpOwogIHdoaWxlICh0LS0pIHsKICAgIG1lbXNldChwcmVmLCAwLCBzaXplb2YgcHJlZik7CiAgICBtZW1zZXQoYWN0aXZlLCAwLCBzaXplb2YgYWN0aXZlKTsKICAgIAogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKSB7CiAgICAgIHNjYW5mKCIlZCIsIGEgKyBpKTsKICAgIH0KICAgIAogICAgbG9uZyBsb25nIGFucyA9IDA7CiAgICAKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkgKz0gQikgewogICAgICBpbnQgbCA9IGksIHIgPSBtaW4obiwgaSArIEIgLSAxKTsKCiAgICAgIGxvbmcgbG9uZyBpbnNpZGUgPSAwOwogICAgICBmb3IgKGludCBqID0gbDsgaiA8PSByOyArK2opIHsKICAgICAgICBmb3IgKGludCBrID0gaiArIDE7IGsgPD0gcjsgKytrKSB7CiAgICAgICAgICBpZiAoYVtrXSA+IGFbal0pIHsKICAgICAgICAgICAgaW5zaWRlICs9IChsb25nIGxvbmcpIGFjdGl2ZVthW2tdIC0gYVtqXV07CiAgICAgICAgICAgIGluc2lkZSArPSAobG9uZyBsb25nKSBwcmVmW2Fba10gLSBhW2pdXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKythY3RpdmVbYVtqXV07CiAgICAgIH0KICAgICAgYW5zICs9IGluc2lkZTsKICAgICAgCiAgICAgIGlmIChpID4gMSkgewogICAgICAgIHNxdWFyZSgpOwogICAgICAgIGxvbmcgbG9uZyBvdXRzaWRlID0gMDsKICAgICAgICBmb3IgKGludCBqID0gbDsgaiA8PSByOyArK2opIHsKICAgICAgICAgIGxvbmcgbG9uZyBhZGQgPSBmbG9vcihmW2Fbal1dLnggKyAwLjUpOwogICAgICAgICAgaWYgKCEoYVtqXSAmIDEpKSBhZGQgLT0gcHJlZlthW2pdID4+IDFdOwogICAgICAgICAgb3V0c2lkZSArPSAoYWRkID4+IDEpOwogICAgICAgIH0KICAgICAgICBhbnMgKz0gb3V0c2lkZTsKICAgICAgfQogICAgICAKICAgICAgZm9yIChpbnQgaiA9IGw7IGogPD0gcjsgKytqKSB7CiAgICAgICAgKytwcmVmW2Fbal1dOwogICAgICAgIC0tYWN0aXZlW2Fbal1dOwogICAgICB9CiAgICB9CgogICAgcHJpbnRmKCIlbGxkXG4iLCBhbnMpOwogIH0KICByZXR1cm4gMDsKfQoK