#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define rep1(i,x,y) for(register int i=x;i>=y;--i)
#define int long long
#define fire signed
#define il inline
template<class T> il void print(T x) {
if(x<0) printf("-"),x=-x;
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
template<class T> il void in(T &x) {
x = 0; char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {if(ch=='-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); }
x *= f;
}
int T=1;
int n,m,q;
const int N=2e5+10;
const int K=66;
const int mod=1e9+7;
int f[N][K],g[N][K];
int sum[N];
string s;
void solve() {
in(n),in(m),in(q);
cin>>s;
s=" "+s;
int lsts=false;
rep(i,1,n) sum[i]=sum[i-1]+(s[i]-'0');
rep(i,1,n) if(s[i]=='1') lsts=i;
// cout<<floor(-1/)
rep(i,1,n) {
int lst=n-i;
if(lst>=m) {
int l=i+1,r=i+m,res=0;
int cnt=sum[r]-sum[i];
while(l<=r) {
int mid=l+r>>1;
if(sum[mid]-sum[i]>=cnt) r=mid-1,res=mid;
else l=mid+1;
}
f[i][0]=res;
g[i][0]=false;
}else {
int yu=m-lst;
if(yu%n==false) {
f[i][0]=lsts;
g[i][0]=(yu-lsts)/n+1;
}else {
int nn=yu;
yu%=n;
if(sum[yu]==0) {
if(nn<lsts&&i<lsts) {
f[i][0]=lsts;
g[i][0]=false;
continue;
}
if(nn>=n) {
f[i][0]=lsts;
g[i][0]=floor(1.0*(nn-lsts-yu)/n)+1;
continue;
}
f[i][0]=i%n+1,g[i][0]=floor(1.0*(nn-f[i][0])/n)+1;
}else {
int l=1,r=yu,res=0;
while(l<=r) {
int mid=l+r>>1;
if(sum[mid]>=sum[yu]) r=mid-1,res=mid;
else l=mid+1;
}
f[i][0]=res;
g[i][0]=floor(1.0*(nn-res)/n)+1;
}
}
}
}
rep(i,1,n) g[i][0]%=mod;
// rep(i,1,n) cout<<f[i][0]<<' ';
rep(j,1,62) {
rep(i,1,n) {
f[i][j]=f[f[i][j-1]][j-1];
g[i][j]=(g[i][j-1]+g[f[i][j-1]][j-1])%mod;
}
}
while(q--) {
int st,k;
in(st),in(k);
if(k==0) {
cout<<st%mod<<endl;
continue;
}
int pl=false,ed=false;
int cc=false;
if(st%n==0) {
cc=st/n;
cc--;
st=n;
}else {
cc=st/n;
st%=n;
}
cc%=mod;
rep1(j,62,0) {
if(k>=(1ll<<j)) {
k-=(1ll<<j);
pl+=g[st][j];
pl%=mod;
st=ed=f[st][j];
}
}
printf("%lld\n",(cc*n%mod+pl*n%mod+ed)%mod);
}
}
fire main() {
while(T--) {
solve();
}
return false;
}
思路应该是对的。