#include<bits/stdc++.h>
#define ll long long
#define nl '\n'
#define F first
#define S second
#define all(a) (a.begin()),(a.end())
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define ms(a,b) memset(a, b, sizeof(a))
#define Input freopen("in.txt","r",stdin)
#define Output freopen("out.txt","w",stdout)
#define MOD 1000000007
using namespace std;
const int N = 2e5 + 5;
ll sum[N];
void Solve(int t)
{
ll n, k, d;
cin >> n >> k >> d;
std::vector<ll> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
sum[i] = sum[i - 1] + v[i];
}
vector<pair<ll, ll>> res;
for (int i = k; i <= n; i++)
{
ll cnt = sum[i] - sum[i - k];
if (cnt % d == 0) {
res.push_back({cnt == k, -(i - k + 1)});
}
}
if (res.size() == 0) {
cout << "-1\n";
}
else {
sort(all(res));
reverse(all(res));
cout << -res[0].S << nl;
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t, T = 1;
cin >> T;
for (t = 1; t <= T; t++)
Solve(t);
return 0;
}