/*
* Name : Md. Fahmidur Rahman Nafi
* Date : 2025-04-06 Time : 20:50:15
*/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
#define lcm(a,b) ((a*b)/__gcd(a,b))
#define debug(x) cout << "Debug : " << x << endl;
const double PI = 2 * acos(0.0);
const int MOD = 1000000007;
void solve(){
int n, k, d;
cin >> n >> k >> d;
vector <ll> a(n);
for (auto &i : a) cin >> i;
ll left = 0, right = 0, sum = 0, pro = 1, zero = 0;
pair <ll, ll> ans = {LLONG_MIN, LLONG_MIN};
while (right < n){
sum += a[right];
if (a[right] == 0){
zero++;
pro = 0;
}
else{
pro *= a[right];
}
while (right - left + 1 > k){
sum -= a[left];
if (a[left] != 0){
pro /= a[left];
}
else{
zero--;
if (zero == 0){
pro = 1;
for (int i = left + 1; i <= right; i++){
pro *= a[i];
}
}
}
left++;
}
if (right - left + 1 == k && sum % d == 0){
if (ans.first < pro){
ans.first = pro;
ans.second = left + 1;
}
}
right++;
}
cout << (ans.first == LLONG_MIN ? -1 : ans.second) << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}