![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/56de97219f3d07e10f31c4eae2238a9e.png)
Input:
5
1003004
4 1
1 2 1
179572007
4 2
2 7 3
2 7 4
111
2 1
2 2 6
0000
1 2
1 4 0
1 4 1
484
1 5
2 2 0
2 3 7
1 2 5
3 3 8
2 2 6
Output:
2 4
1 5
1 2
-1 -1
1 2
-1 -1
1 3
1 3
-1 -1
-1 -1
-1 -1
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e8ddaa3d47165cad2910809994d1c06c.png)
#include<bits/stdc++.h>
#define pb(__x__) push_back(__x__)
#define IOS ios::sync_with_stdio(0);cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
IOS;
int _;
cin>>_;
while(_--){
string s;
cin>>s;
int len = s.size();
s = "*" + s;
int sum[s.size()+1];
memset(sum,0,sizeof(sum));
for(int i = 1;i < s.size();i++){
sum[i] = sum[i-1] + s[i] - '0';
}
int w,m;
cin>>w>>m;
vector<int> v[9];
for(int i = 1;i + w - 1 < s.size();i++){
int L = i,R = i + w - 1;
v[(sum[R] - sum[L - 1]) % 9].pb(i);
}
while(m--){
int a,b,k;
cin>>a>>b>>k;
int x = (sum[b] - sum[a - 1])%9;
vector<int> ans;
ans.pb(len);
ans.pb(len);
for(int i = 0;i < 9;i++){
if(v[i].size() > 1 && (i * x + i)%9 == k){
ans = min(ans,{v[i][0],v[i][1]});
}
for(int j = 0;j < 9;j++){
if(i == j) continue;
if(v[j].size() && v[i].size()&& (i * x + j)%9 == k){
ans = min(ans,{v[i][0],v[j][0]});
}
}
}
if(ans[0] == len){
cout<<"-1 -1\n";
}else{
cout<<ans[0]<<" "<<ans[1]<<"\n";
}
}
}
}