#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int q;
cin >> q;
int n, k;
cin >> n >> k;
int a[n + 1];
map<int, int> b;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int dem = 0, dem2 = 0, ans=0;
for (int l = 1, r = 1; r <= n; r++) {
if (b[a[r]] == 0) {
dem++;
b[a[r]]=1;
}
else b[a[r]]++;
while (dem > k) {
b[a[l]]--;
if (b[a[l]] == 0) {
dem--;
}
l++;
}
ans += r - l + 1;
}
cout << ans << "\n";
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2RlZmluZSBpbnQgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnNpZ25lZCBtYWluKCkgewogICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTtjb3V0LnRpZShOVUxMKTsKICAgIGludCBxOwogICAgY2luID4+IHE7CiAgICBpbnQgbiwgazsKICAgIGNpbiA+PiBuID4+IGs7CiAgICBpbnQgYVtuICsgMV07CiAgICBtYXA8aW50LCBpbnQ+IGI7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICBjaW4gPj4gYVtpXTsKICAgIH0KICAgIGludCBkZW0gPSAwLCBkZW0yID0gMCwgYW5zPTA7CiAgICBmb3IgKGludCBsID0gMSwgciA9IDE7IHIgPD0gbjsgcisrKSB7CiAgICAgICAgaWYgKGJbYVtyXV0gPT0gMCkgewogICAgICAgICAgICBkZW0rKzsKICAgICAgICAgICAgYlthW3JdXT0xOwogICAgICAgIH0KICAgICAgICBlbHNlIGJbYVtyXV0rKzsKICAgICAgICB3aGlsZSAoZGVtID4gaykgewogICAgICAgICAgICBiW2FbbF1dLS07CiAgICAgICAgICAgIGlmIChiW2FbbF1dID09IDApIHsKICAgICAgICAgICAgICAgIGRlbS0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGwrKzsKICAgICAgICB9CiAgICAgICAgYW5zICs9IHIgLSBsICsgMTsKICAgIH0KICAgIGNvdXQgPDwgYW5zIDw8ICJcbiI7CiAgICByZXR1cm4gMDsKfQo=