#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;

int const nmax = 200000;
int v[1 + nmax];
set<int> myset;
map<int,int> code;

void makemove(int &start, int &l){
  set<int>::iterator it = myset.lower_bound(start + l + 1);
  set<int>::iterator it2 = myset.lower_bound(start - l);
  it--;
  if(start < *it){
    l -= (*it - start);
    start = *it;
  } else if(*it2 < start){
    l -= (start - *it2);
    start = *it2;
  }
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;
  for(int i = 1;i <= n; i++){
    cin >> v[i];
    myset.insert(v[i]);
    code[v[i]] = i;
  }
  for(int i = 1; i <= q; i++){
    int start, l;
    cin >> start >> l;
    start = v[start];
    while(true){
      int start1 = start, l1 = l;
      makemove(start, l);
      makemove(start, l);
      if(start == start1 && l != l1)
        l %= (l1 - l);
      else if(l == l1)
        break;
    }
    cout << code[start] << '\n';
  }
  return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;

int const nmax = 200000;
int v[1 + nmax];
set<int> myset;
map<int,int> code;

void makemove(int &start, int &l){
  set<int>::iterator it = myset.lower_bound(start + l + 1);
  set<int>::iterator it2 = myset.lower_bound(start - l);
  it--;
  if(start < *it){
    l -= (*it - start);
    start = *it;
  } else if(*it2 < start){
    l -= (*it2 - start);
    start = *it2;
  }
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;
  for(int i = 1;i <= n; i++){
    cin >> v[i];
    myset.insert(v[i]);
    code[v[i]] = i;
  }
  for(int i = 1; i <= q; i++){
    int start, l;
    cin >> start >> l;
    start = v[start];
    while(true){
      int start1 = start, l1 = l;
      makemove(start, l);
      makemove(start, l);
      if(start == start1 && l != l1)
        l %= (l1 - l);
      else if(l == l1)
        break;
    }
    cout << code[start] << '\n';
  }
  return 0;
}


#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
using ll = long long;

int const nmax = 200000;
int v[1 + nmax];
set<int> myset;
map<int,int> code;

void makemove(int &start, int &l){
  set<int>::iterator it = myset.lower_bound(start + l + 1);
  set<int>::iterator it2 = myset.lower_bound(start - l);
  it--;
  if(start < *it){
    l -= (*it - start);
    start = *it;
  } else if(*it2 < start){
    l -= (*it2 - start);
    start = *it2;
  }
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q;
  cin >> n >> q;
  for(int i = 1;i <= n; i++){
    cin >> v[i];
    myset.insert(v[i]);
    code[v[i]] = i;
  }
  for(int i = 1; i <= q; i++){
    int start, l;
    cin >> start >> l;
    start = v[start];
    while(true){
      int start1 = start1, l1 = l;
      makemove(start, l);
      makemove(start, l);
      if(start == start1 && l != l1)
        l %= (l1 - l);
      else if(l == l1)
        break;
    }
    cout << code[start] << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 2e5 + 1;
int n, q;

int ind[N];
pii x[N];

int calc_forward(int, int);
int calc_backward(int, int);

void input() {
    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> x[i].xx;
        x[i].yy = i;
    }
    sort(x, x + n);
    for(int i = 0; i < n; ++i) {
        ind[x[i].yy] = i;
    }
}

int calc_forward(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return calc_backward(i, l);
    }
    int d = l / (x[j].xx - x[i].xx);
    if(d & 1) {
        return calc_backward(j, l % (x[j].xx - x[i].xx));
    } else {
        return calc_forward(i, l % (x[j].xx - x[i].xx));
    }
}

int calc_backward(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = lb(x, x + n, mp(x[i].xx - l, 0)) - x;
    if(i == j) {
        return calc_forward(i, l);
    }
    int d = l / (x[i].xx - x[j].xx);
    if(d & 1) {
        return calc_forward(j, l % (x[i].xx - x[j].xx));
    } else {
        return calc_backward(i, l % (x[i].xx - x[j].xx));
    }
}

int iterate(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return calc_forward(i, l);
    }
    return calc_backward(j, l - (x[j].xx - x[i].xx));
}

void solve() {
    for(int i = 0; i < q; ++i) {
        int a; cin >> a;
        int l; cin >> l;
        cout << iterate(ind[a - 1], l) + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int n, q;

int ind[N];
pii x[N];

int calc_forward(int, int);
int calc_backward(int, int);

void input() {
    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> x[i].xx;
        x[i].yy = i;
    }
    sort(x, x + n);
    for(int i = 0; i < n; ++i) {
        ind[x[i].yy] = i;
    }
}

int calc_forward(int i, int l) {
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return x[i].yy;
    }
    int d = l / (x[j].xx - x[i].xx);
    if(d & 1) {
        return calc_backward(j, l % (x[j].xx - x[i].xx));
    } else {
        return calc_forward(i, l % (x[j].xx - x[i].xx));
    }
}

int calc_backward(int i, int l) {
    int j = lb(x, x + n, mp(x[i].xx - l, 0)) - x;
    if(i == j) {
        return x[i].yy;
    }
    int d = l / (x[i].xx - x[j].xx);
    if(d & 1) {
        return calc_forward(j, l % (x[i].xx - x[j].xx));
    } else {
        return calc_backward(i, l % (x[i].xx - x[j].xx));
    }
}

int iterate(int i, int l) {
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return x[i].yy;
    }
    return calc_backward(j, l - (x[j].xx - x[i].xx));
}

void solve() {
    for(int i = 0; i < q; ++i) {
        int a; cin >> a;
        int l; cin >> l;
        cout << iterate(ind[a - 1], l) + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 1e5 + 1;
int n, q;

int ind[N];
pii x[N];

int calc_forward(int, int);
int calc_backward(int, int);

void input() {
    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> x[i].xx;
        x[i].yy = i;
    }
    sort(x, x + n);
    for(int i = 0; i < n; ++i) {
        ind[x[i].yy] = i;
    }
}

int calc_forward(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return calc_backward(i, l);
    }
    int d = l / (x[j].xx - x[i].xx);
    if(d & 1) {
        return calc_backward(j, l % (x[j].xx - x[i].xx));
    } else {
        return calc_forward(i, l % (x[j].xx - x[i].xx));
    }
}

int calc_backward(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = lb(x, x + n, mp(x[i].xx - l, 0)) - x;
    if(i == j) {
        return calc_forward(i, l);
    }
    int d = l / (x[i].xx - x[j].xx);
    if(d & 1) {
        return calc_forward(j, l % (x[i].xx - x[j].xx));
    } else {
        return calc_backward(i, l % (x[i].xx - x[j].xx));
    }
}

int iterate(int i, int l) {
    if((i == 0 || x[i - 1].xx + l < x[i].xx) && (i == n - 1 || x[i].xx + l < x[i + 1].xx)) {
        return x[i].yy;
    }
    int j = prev(ub(x, x + n, mp(x[i].xx + l, inf))) - x;
    if(i == j) {
        return calc_forward(i, l);
    }
    return calc_backward(j, l - (x[j].xx - x[i].xx));
}

void solve() {
    for(int i = 0; i < q; ++i) {
        int a; cin >> a;
        int l; cin >> l;
        cout << iterate(ind[a - 1], l) + 1 << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>

using namespace std;

#define debug(a) cerr << #a << ": " << a << endl

typedef long long ll;
typedef pair<int, int> pii;

#define x first
#define y second

const int N = 2e5 + 10;

int n, m;
int x[N];
int qid[N], xid[N];

pii loopOnce(int at, int len) {
	int at1 = upper_bound(x + 1, x + n + 1, x[at] + len) - x - 1;
	int len1 = len - (x[at1] - x[at]);

	int at2 = lower_bound(x + 1, x + n + 1, x[at1] - len1) - x;
	int len2 = len1 - (x[at1] - x[at2]);

	return {at2, len2};
}

int solve(int at, int len) {
	pii p = loopOnce(at, len);

	if (p.x != at) return solve(p.x, p.y);

	int lenChange = len - p.y;
	if (lenChange == 0) return at;
	len %= lenChange;
	return solve(at, len);
}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> m;
	for (int i = 1; i <= n; i++) scanf("%d", &x[i]);

	iota(qid + 1, qid + n + 1, 1);
	sort(qid + 1, qid + n + 1, [](int i, int j) {return x[i] < x[j];});
	for (int i = 1; i <= n; i++) xid[qid[i]] = i;

	sort(x + 1, x + n + 1);

	while (m--) {
		int at, len;
		scanf("%d %d", &at, &len);
		printf("%d\n", qid[solve(xid[at], len)]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define debug(a) cerr << #a << ": " << a << endl

typedef long long ll;
typedef pair<int, int> pii;

#define x first
#define y second

const int N = 2e5 + 10;

int n, m;
int x[N];

pii loopOnce(int at, int len) {
	int at1 = upper_bound(x + 1, x + n + 1, x[at] + len) - x - 1;
	int len1 = len - (x[at1] - x[at]);

	int at2 = lower_bound(x + 1, x + n + 1, x[at1] - len1) - x;
	int len2 = len1 - (x[at1] - x[at2]);

	return {at2, len2};
}

int solve(int at, int len) {
	pii p = loopOnce(at, len);

	if (p.x != at) return solve(p.x, p.y);

	int lenChange = len - p.y;
	if (lenChange == 0) return at;
	len %= lenChange;
	return solve(at, len);
}

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	cin >> n >> m;
	for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
	sort(x + 1, x + n + 1);

	while (m--) {
		int at, len;
		scanf("%d %d", &at, &len);
		printf("%d\n", solve(at, len));
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
vii W;
int T[200005];
int s,l,last=-1;
bool czy=0;
void make_move(int r)
{
    if(r==0)
    {
        last=s;
        auto x=upper_bound(W.begin(),W.end(),mp(W[s].st+l,inf))-W.begin()-1;
        l-=W[x].st-W[s].st;
        s=x;
    }
    else
    {
        auto x=lower_bound(W.begin(),W.end(),mp(W[s].st-l,0))-W.begin();
        int d=W[s].st-W[x].st;
        l-=d;
        if(s==x)
        {
            czy=1;
            return;
        }
        if(s==last)
            l=l%(2*d);
        s=x;
    }
}
int main()
{
    speed
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        W.pb(mp(a,i));
    }
    sort(W.begin(),W.end());
    for(int i=0;i<W.size();i++)
        T[W[i].nd]=i;
    for(int i=1;i<=q;i++)
    {
        cin>>s>>l;
        s=T[s];
        while(!czy)
        {
            make_move(0);
            make_move(1);
        }
        czy=0;
        last=-1;
        cout<<W[s].nd<<"\n";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
vii W;
int T[200005];
int s,l,last=-1;
bool czy=0;
vi R;
void make_move(int r)
{
    R.pb(s);
    if(r==0)
    {
        last=s;
        auto x=upper_bound(W.begin(),W.end(),mp(W[s].st+l,inf))-W.begin()-1;
        l-=W[x].st-W[s].st;
        s=x;
    }
    else
    {
        auto x=lower_bound(W.begin(),W.end(),mp(W[s].st-l,-inf))-W.begin();
        ll d=W[s].st-W[x].st;
        l-=d;
        if(s==x)
        {
            czy=1;
            return;
        }
        s=x;
        if(s==last)
            l=l%(d*2);
    }
}
int main()
{
    speed
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        W.pb(mp(a,i));
    }
    sort(W.begin(),W.end());
    for(int i=0;i<W.size();i++)
        T[W[i].nd]=i;
    for(int i=1;i<=q;i++)
    {
        cin>>s>>l;
        s=T[s];
        while(!czy)
        {
            make_move(0);
            make_move(1);
        }
        czy=0;
        last=-1;
        cout<<W[s].nd<<"\n";
        R.clear();
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
vii W;
int T[200005];
int s,l,last=-1;
bool czy=0;
int licz=0;
void make_move(int r)
{
    licz++;
    if(r==0)
    {
        last=s;
        auto x=upper_bound(W.begin(),W.end(),mp(W[s].st+l,inf))-W.begin()-1;
        l-=W[x].st-W[s].st;
        s=x;
    }
    else
    {
        auto x=lower_bound(W.begin(),W.end(),mp(W[s].st-l,0))-W.begin();
        int d=W[s].st-W[x].st;
        l-=d;
        if(s==x)
        {
            czy=1;
            return;
        }
        if(s==last)
            l=l%(2*d);
        s=x;
    }
}
int main()
{
    speed
    int n,q;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        int a;
        cin>>a;
        W.pb(mp(a,i));
    }
    sort(W.begin(),W.end());
    for(int i=0;i<W.size();i++)
        T[W[i].nd]=i;
    for(int i=1;i<=q;i++)
    {
        if(licz>200000000)
        {
            cout<<"FUCK";
            return 0;
        }
        cin>>s>>l;
        s=T[s];
        while(!czy)
        {
            make_move(0);
            make_move(1);
        }
        czy=0;
        last=-1;
        cout<<W[s].nd<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

const int MAXN = 2e5 + 10;
const int LEFT = 0, RIGHT = 1;
typedef std::pair<int, int> pi;
pi li[MAXN];
int A[MAXN], at[MAXN], n, Q;
int go(int x, int L, int dire) {
	int l = 1, r = n, ans = x;
	(dire ? l : r) = x;
	while (l <= r) {
		int mid = l + r >> 1;
		if (std::abs(A[mid] - A[x]) <= L)
			ans = mid, dire ? (l = mid + 1) : (r = mid - 1);
		else dire ? (r = mid - 1) : (l = mid + 1);
	}
	return ans;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> Q;
	for (int i = 1; i <= n; ++i)
		std::cin >> A[i], li[i] = pi(A[i], i);
	std::sort(li + 1, li + 1 + n);
	for (int i = 1; i <= n; ++i) {
		A[i] = li[i].first;
		at[li[i].second] = i;
	}
	while (Q --> 0) {
		int lst = -1, u, L, dire = RIGHT;
		std::cin >> u >> L; u = at[u];
		while (true) {
			int to = go(u, L, dire);
			if (to == lst) {
				int d = std::abs(A[to] - A[u]);
				if (d == 0) break;
				int c = L / d;
				dire ^= c & 1;
				if (c & 1) std::swap(u, lst);
				L -= c * d;
			} else {
				dire ^= 1;
				L -= std::abs(A[to] - A[u]);
				lst = u, u = to;
			}
		}
		std::cout << li[u].second << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

const int MX = 2e5 + 5;
int n, m;
vii x;

int getNext(int i, int len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, int len, bool dir) {
	db(curr, prev, x[curr], x[prev], len, dir);
	int next = getNext(curr, len, dir);
	db(next);
	if (next == prev) {
		len %= (2 * d(curr, next));
		next = getNext(curr, len, dir);
	}
	if (next == curr)
		return curr;
	return solve(next, curr, len - d(curr, next), !dir);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> n >> m;
	x.assign(n + 1, pii());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		db(idxToSortedIdx[a]);
		cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int n, m;
V<pair<ll, int>> x;

int getNext(int i, ll len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}
int it = 10;

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	db(INT_MAX);

	cin >> n >> m;
	x.assign(n + 1, pair<ll, int>());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		if (n == 1)
			cout << "1\n";
		else {
			a = idxToSortedIdx[a];
			int next = getNext(a, l, 0);
			l -= d(next, a);
			int curr = next;
			bool dir = 1;
			while (true) {
				int next = getNext(curr, l, dir);
				if (next == curr)
					break;
				int D = d(curr, next);
				if ((l / D) % 2 == 1)
					dir = !dir, curr = next;
				l %= D;
			}
			cout << x[curr].sc << '\n';
		}
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

const int MX = 2e5 + 5;
int n, m;
vii x;

int getNext(int i, int len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

int d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, int len, bool dir) {
	db(curr, prev, x[curr], x[prev], len, dir);
	int next = getNext(curr, len, dir);
	db(next);
	if (next == prev) {
		len %= (2 * d(curr, next));
		next = getNext(curr, len, dir);
	}
	if (next == curr)
		return curr;
	return solve(next, curr, len - d(curr, next), !dir);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> n >> m;
	x.assign(n + 1, pii());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin(), x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		db(idxToSortedIdx[a]);
		cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int n, m;
V<pair<ll, int>> x;

int getNext(int i, ll len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, ll len, bool dir) {
	int next = getNext(curr, len, dir);
	db(next);
	if (next == prev) {
		len %= (2 * d(curr, next));
		next = getNext(curr, len, dir);
	}
	if (next == curr) {
		int othNext = getNext(curr, len, !dir);
		if (othNext == curr)
			return curr;
		next = othNext;
		dir = !dir;
	}
	return solve(next, curr, len - d(curr, next), !dir);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	db(INT_MAX);

	cin >> n >> m;
	x.assign(n + 1, pair<ll, int>());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		if (n == 1)
			cout << "1\n";
		else
			db(idxToSortedIdx[a]), cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int n, m;
V<pair<ll, int>> x;

int getNext(int i, ll len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, ll len, bool dir, bool f = true) {
	if ((curr == n && !dir) || (curr == 1 && dir))
		return solve(curr, prev, len, !dir, f);
	if (f) {
		int next = getNext(curr, len, dir);
		db(f, next, len - d(curr, next));
		return solve(next, curr, len - d(curr, next), !dir, 0);
	}
	int next = getNext(curr, len, dir);
	if (next == curr)
		return curr;
	db(next);
	int D = d(curr, next);
	if ((len / D) % 2 == 1)
		dir = !dir, curr = next;
	len %= D;
	db(curr, len, dir);
	return solve(getNext(curr, len, dir), curr, len - d(curr, next), !dir, 0);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	db(INT_MAX);

	cin >> n >> m;
	x.assign(n + 1, pair<ll, int>());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		if (n == 1)
			cout << "1\n";
		else
			db(idxToSortedIdx[a]), cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int n, m;
V<pair<ll, int>> x;

int getNext(int i, ll len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, ll len, bool dir) {
	if ((curr == n && !dir) || (curr == 1 && dir))
		return solve(curr, prev, len, !dir);
	int next = getNext(curr, len, dir);
	db(next);
	if (next == prev) {
		len %= (2 * d(curr, next));
		next = getNext(curr, len, dir);
	}
	if (next == curr)
		return curr;
	return solve(next, curr, len - d(curr, next), !dir);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);
	db(INT_MAX);

	cin >> n >> m;
	x.assign(n + 1, pair<ll, int>());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		if (n == 1)
			cout << "1\n";
		else
			db(idxToSortedIdx[a]), cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int n, m;
vii x;

int getNext(int i, int len, bool dir) {
	if (!dir)
		return upper_bound(x.begin() + 1, x.end(), mp(x[i].fs + len, int(2e9))) - x.begin() - 1;
	else
		return lower_bound(x.begin() + 1, x.end(), mp(x[i].fs - len, -1)) - x.begin();
}

ll d(int i, int j) {
	return abs(x[i].fs - x[j].fs);
}

int solve(int curr, int prev, int len, bool dir) {
	db(curr, n);
	if ((curr == n && !dir) || (curr == 1 && dir))
		return solve(curr, prev, len, !dir);
	db(curr, prev, x[curr], len, dir);
	int next = getNext(curr, len, dir);
	db(next);
	if (next == prev) {
		len %= (2 * d(curr, next));
		next = getNext(curr, len, dir);
	}
	if (next == curr)
		return curr;
	return solve(next, curr, len - d(curr, next), !dir);
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> n >> m;
	x.assign(n + 1, pii());
	for (int i = 1; i <= n; ++i) {
		cin >> x[i].fs;
		x[i].sc = i;
	}
	sort(x.begin() + 1, x.end());
	vi idxToSortedIdx(n + 1);
	for (int i = 1; i <= n; ++i)
		idxToSortedIdx[x[i].sc] = i;

	db(x, idxToSortedIdx);

	int a, l;
	for (int i = 1; i <= m; ++i) {
		cin >> a >> l;
		if (n == 1)
			cout << "1\n";
		else
			db(idxToSortedIdx[a]), cout << x[solve(idxToSortedIdx[a], -1, l, 0)].sc << '\n';
	}

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 24;
int n , m;
int pos[maxn];
pair <int , int> x[maxn];
int dis(int fi , int se){
    return abs(x[fi].first - x[se].first);
}

//0 right 1 left
int get_next(int id , bool direc , int len){
    if (direc == 0){
        int l = id , r = n + 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (dis(mid , id) <= len){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        return l;
    }
    int l = 0 , r = id;
    while (r - l > 1){
        int mid = (l + r) / 2;
        if (dis(mid , id) <= len){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return r;
}

int solve(int id , bool direc , int len){
    int nex = get_next(id , direc , len);
    if (nex == id) return id;
    int disd = dis(id , nex);
    if ((len / disd) % 2 == 1) return solve(nex , direc ^ 1 , len % disd);
    return solve(nex , direc , len % disd);
}
int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        int x1;
        cin >> x1;
        x[i].first = x1;
        x[i].second = i;
    }
    sort(x + 1 , x + n + 1);
    for (int i = 1; i <= n; i++){
        pos[x[i].second] = i;
    }
    for (int i = 0; i < m; i++){
        int id , l;
        cin >> id >> l;
        id = pos[id];
        int nex = get_next(id , 0 , l);
        cout << solve(nex , 1 , l - dis(id , nex)) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 24;
int n , m;
int pos[maxn];
pair <int , int> x[maxn];
int dis(int fi , int se){
    return abs(x[fi].first - x[se].first);
}

//0 right 1 left
int get_next(int id , bool direc , int len){
    if (direc == 0){
        int l = id , r = n + 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (dis(mid , id) <= len){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        return l;
    }
    int l = 0 , r = id;
    while (r - l > 1){
        int mid = (l + r) / 2;
        if (dis(mid , id) <= len){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return r;
}

int solve(int id , bool direc , int len){
    int nex = get_next(id , direc , len);
    if (nex == id) return x[id].second;
    int disd = dis(id , nex);
    if ((len / disd) % 2 == 1) return solve(nex , direc ^ 1 , len % disd);
    return solve(nex , direc , len % disd);
}
int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        int x1;
        cin >> x1;
        x[i].first = x1;
        x[i].second = i;
    }
    sort(x + 1 , x + n + 1);
    for (int i = 1; i <= n; i++){
        pos[x[i].second] = i;
    }
    for (int i = 0; i < m; i++){
        int id , l;
        cin >> id >> l;
        id = pos[id];
        int nex = get_next(id , 0 , l);
        cout << solve(nex , 1 , l - dis(id , nex)) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 24;
int n , m;
int pos[maxn];
pair <int , int> x[maxn];
int dis(int fi , int se){
    return abs(x[fi].first - x[se].first);
}

//0 right 1 left
int get_next(int id , bool direc , int len){
    if (direc == 0){
        int l = id , r = n + 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (dis(mid , id) <= len){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        return l;
    }
    int l = 0 , r = id;
    while (r - l > 1){
        int mid = (l + r) / 2;
        if (dis(mid , id) <= len){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return r;
}

int solve(int id , bool direc , int len){
    int nex = get_next(id , direc , len);
    if (nex == id) return id;
    int disd = dis(id , nex);
    if ((len / disd) % 2 == 1) return solve(nex , !direc , len % disd);
    return solve(nex , direc , len % disd);
}
int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        int x1;
        cin >> x1;
        x[i].first = x1;
        x[i].second = i;
    }
    sort(x + 1 , x + n + 1);
    for (int i = 1; i <= n; i++){
        pos[x[i].second] = i;
    }
    for (int i = 0; i < m; i++){
        int id , l;
        cin >> id >> l;
        id = pos[id];
        int nex = get_next(id , 0 , l);
        cout << solve(nex , 1 , l - dis(id , nex)) << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 24;
int n , m;
int pos[maxn];
pair <int , int> x[maxn];
int dis(int fi , int se){
    return abs(x[fi].first - x[se].first);
}

//0 right 1 left
int get_next(int id , bool direc , int len){
    if (direc == 0){
        int l = id , r = n + 1;
        while (r - l > 1){
            int mid = (l + r) / 2;
            if (dis(mid , id) <= len){
                l = mid;
            }
            else{
                r = mid;
            }
        }
        return l;
    }
    int l = 0 , r = id;
    while (r - l > 1){
        int mid = (l + r) / 2;
        if (dis(mid , id) <= len){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    return r;
}

int solve(int id , bool direc , int len){
    int nex = get_next(id , direc , len);
    if (nex == id) return x[id].second;
    int disd = dis(id , nex);
    if ((len / disd) % 2 == 1) return solve(nex , direc ^ 1 , len % disd);
    return solve(id , direc , len % disd);
}
int main(){
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        int x1;
        cin >> x1;
        x[i].first = x1;
        x[i].second = i;
    }
    sort(x + 1 , x + n + 1);
    for (int i = 1; i <= n; i++){
        pos[x[i].second] = i;
    }
    for (int i = 0; i < m; i++){
        int id , l;
        cin >> id >> l;
        id = pos[id];
        int nex = get_next(id , 0 , l);
        cout << solve(nex , 1 , l - dis(id , nex)) << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

const int N = 200 * 1000 + 20, inf = 2e9 + 1;
int n, x[N], xx[N], m, idx, len;

int dir(int idx) {
	int res = inf;
	if (idx)
		res = x[idx] - x[idx - 1];
	if (idx < n - 1)
		res = min(res, x[idx + 1] - x[idx]);
	return res;
}

int find_right(int idx, int len) {
	int st = idx, en = n, mid;
	while (st < en - 1) {
		mid = st + en >> 1;
		if (x[mid] - x[idx] <= len)
			st = mid;
		else
			en = mid;
	}
	return st;
}

int find_left(int idx, int len) {
	idx = n - idx - 1;
	int st = idx, en = n, mid;
	while (st < en - 1) {
		mid = st + en >> 1;
		if (xx[idx] - xx[mid] <= len)
			st = mid;
		else
			en = mid;
	}
	return n - st - 1;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n; i++)
		xx[i] = x[n - i - 1];
	while (m--) {
		cin >> idx >> len;
		idx--;
		int idx2 = find_right(idx, len);
		int len2 = len - (x[idx2] - x[idx]);
		idx = idx2;
		len = len2;
		idx2 = find_left(idx, len);
		len2 = len - (x[idx] - x[idx2]);
		idx = idx2;
		len = len2;
		while (len >= dir(idx)) {
			idx2 = find_right(idx, len);
			len2 = len - (x[idx2] - x[idx]);
			int idx3 = find_left(idx2, len2);
			int len3 = len3 - (x[idx2] - x[idx3]);
			if (idx3 == idx)
				len %= (len - len3);
			else {
				idx = idx3;
				len = len3;
			}
		}
		cout << idx + 1 << "\n";
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

const int N = 200 * 1000 + 20, inf = 2e9 + 1;
int n, x[N], xx[N], m, idx, len, tmp[N], tmpp[N];

int dir(int idx) {
	int res = inf;
	if (idx)
		res = x[idx] - x[idx - 1];
	if (idx < n - 1)
		res = min(res, x[idx + 1] - x[idx]);
	return res;
}

int find_right(int idx, int len) {
	int st = idx, en = n, mid;
	while (st < en - 1) {
		mid = st + en >> 1;
		if (x[mid] - x[idx] <= len)
			st = mid;
		else
			en = mid;
	}
	return st;
}

int find_left(int idx, int len) {
	idx = n - idx - 1;
	int st = idx, en = n, mid;
	while (st < en - 1) {
		mid = st + en >> 1;
		if (xx[idx] - xx[mid] <= len)
			st = mid;
		else
			en = mid;
	}
	return n - st - 1;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	iota(tmp, tmp + n, 0);
	sort(tmp, tmp + n, [](int i, int j) {
		return x[i] < x[j];
	});
	sort(x, x + n);
	for (int i = 0; i < n; i++)
		tmpp[tmp[i]] = i;
	for (int i = 0; i < n; i++)
		xx[i] = x[n - i - 1];
	while (m--) {
		cin >> idx >> len;
		idx--;
		idx = tmpp[idx];
		int idx2 = find_right(idx, len);
		int len2 = len - (x[idx2] - x[idx]);
		idx = idx2;
		len = len2;
		idx2 = find_left(idx, len);
		len2 = len - (x[idx] - x[idx2]);
		idx = idx2;
		len = len2;
		while (len >= dir(idx)) {
			idx2 = find_right(idx, len);
			len2 = len - (x[idx2] - x[idx]);
			int idx3 = find_left(idx2, len2);
			int len3 = len2 - (x[idx2] - x[idx3]);
			if (idx3 == idx)
				len %= (len - len3);
			else {
				idx = idx3;
				len = len3;
			}
		}
		cout << tmp[idx] + 1 << "\n";
	}
	return 0;

}


#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
int x[200010];
std::vector<int> index;
std::set<int> S;
std::map<int,int> hash;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) hash[x[i]] = i;
	for(int i=1;i<=a;i++) S.insert(x[i]);

	std::set<int> ::iterator it;
	for(int i=1;i<=b;i++)
	{
		int c,d,c2,d2,c3,d3;
		scanf("%d%d",&c,&d);
		c = x[c];
		while(1)
		{
			it = S.upper_bound(c+d);
			if(it==S.begin()) c2 = c, d2 = d;
			else
			{
				it--;
				c2 = (*it);
				d2 = (c+d-c2);
			}

			it = S.lower_bound(c2-d2);
			if(it==S.end()) c3 = c2, d3 = d2;
			else
			{
				c3 = (*it);
				d3 = (c3+d2-c2);
			}
			if(c==c3&&d==d3)
			{
				printf("%d\n",hash[c]);
				break;
			}
			else if(c==c3)
			{
				int l = (d-d3);
				d%=l;
			}
			c = c3, d = d3;
		}
	}
}


#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
int x[200010];
std::vector<int> index;
std::set<int> S;
std::map<int,int> hash;

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) hash[x[i]] = i;
	for(int i=1;i<=a;i++) S.insert(x[i]);

	std::set<int> ::iterator it;
	for(int i=1;i<=b;i++)
	{
		int c,d,c2,d2,c3,d3;
		scanf("%d%d",&c,&d);
		c = x[c];
		while(1)
		{
			it = S.upper_bound(c+d);
			if(it==S.begin()) c2 = c, d2 = d;
			else
			{
				it--;
				c2 = (*it);
				d2 = (c+d-c2);
			}

			it = S.lower_bound(c2-d2);
			if(it==S.end()) c3 = c2, d3 = d2;
			else
			{
				c3 = (*it);
				d3 = (c3+d2-c2);
			}
			if(c==c3&&d==d3)
			{
				printf("%d\n",hash[c]);
				break;
			}
			else if(c==c3)
			{
				int l = (d-d3);
				d3%=l;
			}
			c = c3, d = d3;
		}
	}
}


#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define _file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld long double
#define sp setprecision
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define pii pair < int , int >
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 100;
const ll inf = 1e18;

//Main CODE :/\

int a[maxn] , b[maxn];
map < int , int > mp;
int main(){
	ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	int n , m;
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = a[i];
		mp[a[i]] = i + 1;
	}
	sort(b , b + n);
	for (int i = 0; i < m; i++){
		int t , s , pos , bd , x = 1;
		cin >> t >> s;
		t--;
		pos = upper_bound(b , b + n , a[t]) - b - 1;
		int prv = -1 , z;
		while (2 > 1){
			if (x == 1){
				bd = upper_bound(b , b + n , b[pos] + s) - b - 1;
				z = -b[pos] + b[bd];
			}
			else{
				bd = lower_bound(b , b + n , b[pos] - s) - b;
				z = -b[bd] + b[pos];
			}
			s -= z;
			if (bd == prv && bd == pos)
				break;
			if (bd == prv)
				s %= 2 * z;
			prv = pos;
			pos = bd;
			x ^= 1;
		}
		cout << mp[b[pos]] << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
ll n,k,c,ans,x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        ans=0,c=0,x=0;
        bool y=1;
        cin>>n>>k;
        string s;cin>>s;
        if(s[0]=='0'){
            for(int i=1;i<n;++i){
                if(s[i]=='0')++c;
                else{x=i+1;c=0;y=0;break;}
                if(c==k){
                    s[0]='1';
                    ++ans;x=k+1;c=k;y=0;break;
                }
            }
        }
    else y=0;
    if(y==1&&ans==0){
        cout<<1<< "\n";
        continue;
    }
     //   cout<<x<< " "<<c<< "\n";
        for(int i=x;i<(n-1);++i){
            if(s[i]=='0')++c;
            else c=0;
            if(c>k){
                c=0;
                for(int j=(i+1);j<n;++j){
                    if(s[j]=='0')++c;
                    else break;
                    if(c==k){++ans;s[i]='1';c=0;c+=k;i+=(k+1);break;}
                }
            }
        }
        c=0;
        if(s[n-1]=='0')
        for(int i=(n-2);i>=0;--i){
            if(s[i]=='0')++c;
            else break;
            if(c==k){++ans;s[n-1]='1';break;}
        }
      //  cout<<s<< "\n";
        cout<<ans<< "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
int arr[10009];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        string s;
        cin>>s;
        int c=1,ans=0;
        for(int i=0;i<n;++i){
            if(c==k){
                if(s[i]!='1')++ans;
                c=0;
                continue;
            }
            ++c;
        }
        cout<<ans<< "\n";
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        ll n,k,c=0,ans=0;cin>>n>>k;
        string s;cin>>s;
        if(s[0]=='0'){
            bool x=1;
            for(int i=0;i<=k;++i){
                if(s[i]=='1')x=0;
            }
        if(x)++ans;
        s[0]='1';
        }
        int tmp=1+(k*2);
        for(int i=0;i<n;++i){
            if(s[i]=='0')++c;
            else c=0;
            if(c==tmp)++ans;
        }
        cout<<ans<< "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		int z=0;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				z++;
				if(z==1)
				{
					while( (h-(k+1))>=0 && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				else
				{
					while( (prev+k+1)<=(h-(k+1)) && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				prev=i;
			}
		}
		if(prev>0)
		{

				int h=prev;
				while( (h+k+1)<n)
				{
					count++;
					str[(h+k+1)]='1';
					h+=(k+1);
				}

		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				while( (h-(k+1))>=prev && str[h-(k+1)]=='0' )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		int z=0;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				z++;
				if(z==1)
				{
					while( (h-(k+1))>=0 && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				else
				{
					while( (prev+k+1)<=(h-(k+1)) && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				prev=i;
			}
		}
		if(z>0)
		{

				int h=prev;
				while( (h+k+1)<n)
				{
					count++;
					str[(h+k+1)]='1';
					h+=(k+1);
				}

		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		int z=0;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				z++;
				if(z==1)
				{

				while( (h-(k+1))>=0 && str[h-(k+1)]=='0'   )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}

				}
				else
				{
					while( (prev+k+1)<=(h-(k+1)) && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				prev=i;
			}
		}
		if(prev>0)
		{

				int h=prev;
				while( (h+k+1)<n)
				{
					count++;
					h+=(k+1);
				}

		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=-(k+1);
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				while( (h-(k+1))>prev && str[h-(k+1)]=='0' && prev+k <(h-(k+1))  )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=-(k);
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;

				while( (h-(k+1))>=prev && str[h-(k+1)]=='0' && prev+k <(h-(k+1))  )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=-1;
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				while( (h-(k+1))>prev && str[h-(k+1)]=='0' )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0;
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				while( (h-(k+1))>=0 && str[h-(k+1)]=='0')
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		int z=0;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				z++;
				if(z==1)
				{

				while( (h-(k+1))>=0 && str[h-(k+1)]=='0'   )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}

				}
				else
				{
					while( (prev+k+1)<=(h-(k+1)) && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				prev=i;
			}
		}
		if(prev>0)
		{

				int h=prev;
				while( (h+k+1)<n)
				{
					count++;
					str[(h+k+1)]='1';
					h+=(k+1);
				}

		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=-(k);
		double ans;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				while( (h-(k+1))>prev && str[h-(k+1)]=='0' && prev+k <(h-(k+1))  )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		int cnt=0,count=0,prev=0;
		double ans;
		int z=0;
		for(int i=0;i<str.size();i++)
		{
			if(str[i]=='0')
				cnt++;
			else
			{
				int h=i;
				z++;
				if(z==1)
				{

				while( (h-(k+1))>=0 && str[h-(k+1)]=='0'   )
				{
					count++;
					str[h-(k+1)]='1';
					h=h-(k+1);
				}

				}
				else
				{
					while( (prev+k)>(h-(k+1)) && str[h-(k+1)]=='0'   )
					{
						count++;
						str[h-(k+1)]='1';
						h=h-(k+1);
					}
				}
				prev=i;
			}
		}
		if(cnt==n)
		{
			ans=(n*1.0)/(k+1);
			cout<<ceil(ans)<<endl;
		}
		else
		{
			cout<<count<<endl;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		vector<int>v;
		int count=0;
		for(int i=0;i<n;i++)
		{
			if(str[i]=='0')
				count++;
			else
			{
				if(count!=0)
					v.push_back(count);
				count=0;
			}
		}
		if(count!=0)
			v.push_back(count);
		if(str[0]=='0'&&str[n-1]=='0'&&v.size()==1)
			int a=1;
			//cout<<"Hi1 "<<v.size()<<endl;
		else if(str[0]=='0'&&str[n-1]=='0')
		{
			//cout<<"Hi2"<<endl;
			v[0]-=k;
			for(int i=1;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
		}
		else if(str[0]=='0'&&str[n-1]=='1')
		{
			//cout<<"Hi3"<<endl;
			v[0]-=k;
			for(int i=1;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		else if(str[0]=='1'&&str[n-1]=='0')
		{
			//cout<<"Hi4"<<endl;
			for(int i=0;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
//			for(int i=0;i<v.size();i++)
//			{
//				cout<<"Hi "<<v[i]<<endl;
//			}
		}
		else
		{
			//cout<<"Hi5"<<endl;
			for(int i=0;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		int ans=0;
		for(int i=0;i<v.size();i++)
		{
			//cout<<"V"<<v[i]<<" ";
			//cout<<"Hiiiiii"<<endl;
			if(v[i]>0)
			{
				//cout<<"Hellooooo"<<endl;
				ans+=ceil(v[i]*1.0/(k+1));
			}
		}
		//cout<<"He"<<endl;
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		vector<int>v;
		int count=0;
		for(int i=0;i<n;i++)
		{
			if(str[i]=='0')
				count++;
			else
			{
				if(count!=0)
					v.push_back(count);
				count=0;
			}
		}
		if(count!=0)
			v.push_back(count);
		if(str[0]=='0'&&str[n-1]=='0'&&v.size()==1)
			cout<<ceil(v[0]*1.0/(k+1))<<endl;
		else if(str[0]=='0'&&str[n-1]=='0')
		{
			v[0]-=k;
			for(int i=1;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
		}
		else if(str[0]=='0'&&str[n-1]=='1')
		{
			v[0]-=k;
			for(int i=1;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		else if(str[0]=='1'&&str[n-1]=='0')
		{
			for(int i=0;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
		}
		else
		{
			for(int i=0;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		int ans=0;
		for(int i=0;i<v.size();i++)
		{
			if(v[i]>0)
			{
				ans+=ceil(v[i]*1.0/(k+1));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		vector<int>v;
		int count=0;
		for(int i=0;i<n;i++)
		{
			if(str[i]=='0')
				count++;
			else
			{
				if(count!=0)
					v.push_back(count);
				count=0;
			}
		}
		if(count!=0)
			v.push_back(count);
		if(str[0]=='0'&&str[n-1]=='0'&&v.size()==1)
		{
			cout<<ceil(v[0]*1.0/(k+1))<<endl;
			continue;
		}
		else if(str[0]=='0'&&str[n-1]=='0')
		{
			v[0]-=k;
			for(int i=1;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
		}
		else if(str[0]=='0'&&str[n-1]=='1')
		{
			v[0]-=k;
			for(int i=1;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		else if(str[0]=='1'&&str[n-1]=='0')
		{
			for(int i=0;i<v.size()-1;i++)
			{
				v[i]-=2*k;
			}
			v[v.size()-1]-=k;
		}
		else
		{
			for(int i=0;i<v.size();i++)
			{
				v[i]-=2*k;
			}
		}
		int ans=0;
		for(int i=0;i<v.size();i++)
		{
			if(v[i]>0)
			{
				ans+=ceil(v[i]*1.0/(k+1));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int t;
	cin>>t;
	for(int a=1;a<=t;a++)
	{
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		if(n==1&&str[0]=='1')
		{
			cout<<0<<endl;
			continue;
		}
		if(n==1&&str[0]=='0')
		{
			cout<<1<<endl;
			continue;
		}
		int flag=0;
		for(int i=0;i<str.length();i++)
		{
			if(str[i]=='1')
			{
				flag=1;
				break;
			}
		}
		if(flag==0)
		{
			if(str.length()%(k+1)==0)
				cout<<str.length()/(k+1)<<endl;
			else
				cout<<str.length()/(k+1)+1<<endl;
			continue;
		}
		vector<int>v;
		int count;
		for(int i=0;i<str.length();i++)
		{
			count=0;
			while(str[i]=='0'&&i<str.length())
			{
				count++;
				i++;
			}
			if(count!=0)
			{
				v.push_back(count);
				count=0;
			}
		}
		int res=0;
		if(str[0]=='0'&&str[str.length()-1]=='0')
		{
			res+=v[0]/(k+1);
			res+=v[v.size()-1]/(k+1);
			for(int i=1;i<v.size()-1;i++)
			{
				int q=v[i]/k;
				int r=v[i]%k;
				if(q>=2&&q==r+1)
					res+=r;
				else if(q>=2&&q!=r+1)
					res+=(q-2);
			}
		}
		else if(str[0]=='0'&&str[str.length()-1]!='0')
		{
			res+=v[0]/(k+1);
			for(int i=1;i<v.size();i++)
			{
				int q=v[i]/k;
				int r=v[i]%k;
				if(q>=2&&q==r+1)
					res+=r;
				else if(q>=2&&q!=r+1)
					res+=(q-2);
			}
		}
		else if(str[0]!='0'&&str[str.length()-1]=='0')
		{
			res+=v[v.size()-1]/(k+1);
			for(int i=0;i<v.size()-1;i++)
			{
				int q=v[i]/k;
				int r=v[i]%k;
				if(q>=2&&q==r+1)
					res+=r;
				else if(q>=2&&q!=r+1)
					res+=(q-2);
			}
		}
		else
		{
			for(int i=0;i<v.size();i++)
			{
				int q=v[i]/k;
				int r=v[i]%k;
				if(q>=2&&q==r+1)
					res+=r;
				else if(q>=2&&q!=r+1)
					res+=(q-2);
			}
		}
		cout<<res<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

  long  int n,k,i,j,c=0,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
long  int l=a.find('1');
  if(l==-1)
  {
      for(i=0;i<n;i=i+k+1)
      {

          c++;
      }
      cout<<c<<endl;
      continue;

  }
    c=0;
   for(i=0;i<n-1;i++)
   {
       c=1;
     if(a[i]=='0')
     {
            for(j=i+1;j<n;j++)
            {
                if(a[j]=='1')
                {
                    break;
                }
                c++;

            }

            s+=c/(k+1);
            i=j-1;
     }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


//template owner:professor
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(long long int  i=0;i<n;i++)
#define vi std::vector<int>
const long long int MOD=1e9+7;
#define vli std::vector<long long int>
#define si std::set<int>
#define sli std::set<long long int >
#define qi std::queue<int >
#define qli std::queue<long long int >
#define mli std::map<long long int ,long long int>
#define mc std::map<char, long long int>
#define umli std::unordered_map<long long int,long long int>
#define umc std::unordered_map<char,long long int>
#include<cmath>
#include<bits/stdc++.h>
void solve()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll i,c=0,ans=0;
	vli v;
	bool consta=false;
	rep(i,n)
	{
		if(s[i]=='0')
		c++;
		else
		{
		v.pb(c);
		c=0;
		consta=true;
		}

	}
	v.pb(c);
    for (auto it:v)
    {
    	ans+=(it/(k+1));

    }
    if(!consta)
    {
    if(ans==0)
    ans++;
    }
    cout<<ans<<endl;

}

int main() {
         ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
solve();
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

    int n,k,i,j,c=1,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
  int l=a.find('1');
  if(l==-1)
  {
      l=a.length()/(k+1);
      if(l==0)
      l++;
      cout<<l<<endl;
      continue;
  }
    c=0;
   for(i=0;i<n-1;i++)
   {
       c=1;
     if(a[i]=='0')
     {
            for(j=i+1;j<n;j++)
            {
                if(a[j]=='1')
                {
                    break;
                }
                c++;

            }

            s+=c/(k+1);
            i=j-1;
     }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


//template owner:professor
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(long long int  i=0;i<n;i++)
#define vi std::vector<int>
const long long int MOD=1e9+7;
#define vli std::vector<long long int>
#define si std::set<int>
#define sli std::set<long long int >
#define qi std::queue<int >
#define qli std::queue<long long int >
#define mli std::map<long long int ,long long int>
#define mc std::map<char, long long int>
#define umli std::unordered_map<long long int,long long int>
#define umc std::unordered_map<char,long long int>
#include<cmath>
#include<bits/stdc++.h>
void solve()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll i,c=0,ans=0;
	vli v;
	bool consta=false;
	rep(i,n)
	{
		if(s[i]=='0')
		c++;
		else
		{
		v.pb(c);
		c=0;
		consta=true;
		}

	}
	v.pb(c);
    for (auto it:v)
    {
    	ans+=(it/(k+1));

    }
    if(!consta)
    {
    	ans=1;
    	c--;
    	ans+=c/(k+1);

    }

    cout<<ans<<endl;

}

int main() {
         ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
solve();
}

	// your code goes here
	return 0;
}


//template owner:professor
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(long long int  i=0;i<n;i++)
#define vi std::vector<int>
const long long int MOD=1e9+7;
#define vli std::vector<long long int>
#define si std::set<int>
#define sli std::set<long long int >
#define qi std::queue<int >
#define qli std::queue<long long int >
#define mli std::map<long long int ,long long int>
#define mc std::map<char, long long int>
#define umli std::unordered_map<long long int,long long int>
#define umc std::unordered_map<char,long long int>
#include<cmath>
#include<bits/stdc++.h>
void solve()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll i,c=0,ans=0;
	vli v;
	bool consta=false;
	rep(i,n)
	{
		if(s[i]=='0')
		c++;
		else
		{
		v.pb(c);
		c=0;
		consta=true;
		}

	}
	v.pb(c);
    for (auto it:v)
    {
    	ans+=(it/(k+1));

    }
    if(!consta)
    {

 ll rem=c%(k+1);
 ans=ans+rem/k;
    }
    cout<<ans<<endl;

}

int main() {
         ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
solve();
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

    int n,k,i,c=1,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
  int l=a.find('1');
  if(l==-1)
  {
      l=a.length()/(k+1);
      if(l==0)
      l++;
      cout<<l<<endl;
      continue;
  }
    c=1;
   for(i=1;i<n;i++)
   {
      if(a[i]=='0'&&a[i-1]=='0')
      {
          c++;

      }

      else if((c>1&&a[i]=='1')||i==n-1)
      {

         s+=(c/(k+1));
         c=1;
      }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

  long  int n,k,i,j,c=1,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
long  int l=a.find('1');
  if(l==-1)
  {
      l=a.length()/(k+1);
      if(l==0)
      l++;
      cout<<l<<endl;
      continue;
  }
    c=0;
   for(i=0;i<n-1;i++)
   {
       c=1;
     if(a[i]=='0')
     {
            for(j=i+1;j<n;j++)
            {
                if(a[j]=='1')
                {
                    break;
                }
                c++;

            }

            s+=c/(k+1);
            i=j-1;
     }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


//template owner:professor
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,n) for(long long int  i=0;i<n;i++)
#define vi std::vector<int>
const long long int MOD=1e9+7;
#define vli std::vector<long long int>
#define si std::set<int>
#define sli std::set<long long int >
#define qi std::queue<int >
#define qli std::queue<long long int >
#define mli std::map<long long int ,long long int>
#define mc std::map<char, long long int>
#define umli std::unordered_map<long long int,long long int>
#define umc std::unordered_map<char,long long int>
#include<cmath>
#include<bits/stdc++.h>
void solve()
{
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	ll i,c=0,ans=0;
	vli v;
	bool consta=false;
	rep(i,n)
	{
		if(s[i]=='0')
		c++;
		else
		{
		v.pb(c);
		c=0;
		consta=true;
		}

	}
	v.pb(c);
    for (auto it:v)
    {
    	ans+=(it/(k+1));

    }
    if(!consta)
    {

 ans=(c+1)/(k+1);
    }
    cout<<ans<<endl;

}

int main() {
         ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
solve();
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

  long  int n,k,i,j,c=0,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
long  int l=a.find('1');
  if(l==-1)
  {
      for(i=0;i<n;i=i+k+1)
      {

          c++;
      }
      cout<<c<<endl;
      continue;

  }
    c=0;
   for(i=0;i<n-1;i++)
   {
       c=1;
     if(a[i]=='0')
     {
            for(j=i+1;j<n;j++)
            {
                if(a[j]=='1')
                {
                    break;
                }
                c++;

            }

            s+=c/(k+k);
            i=j-1;
     }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

  long  int n,k,i,j,c=0,s=0,d=0;
    string a;

    cin>>n>>k;
    cin>>a;
long  int l=a.find('1');
  if(l==-1)
  {
      for(i=0;i<n;i=i+k+1)
      {

          c++;
      }
      cout<<c<<endl;
      continue;

  }
    c=0;
   for(i=0;i<n-1;i++)
   {

     if(a[i]=='0')
     {
          d++;
     }
     if(d>k)
     {
         d=0;
         c++;
     }
      if(a[i]=='1')
     {
          d=0;
     }
   }

   cout<<c<<endl;
}

	// your code goes here
	return 0;
}


#include <iostream>
using namespace std;
#include<bits/stdc++.h>
int main() {

int t;
 cin>>t;

while(t--)
{

    int n,k,i,c=1,s=0;
    string a;

    cin>>n>>k;
    cin>>a;
  int l=a.find('1');
  if(l==-1)
  {
      cout<<a.length()/(k+1)<<endl;
      continue;
  }
    c=1;
   for(i=1;i<n;i++)
   {
      if(a[i]=='0'&&a[i-1]=='0')
      {
          c++;

      }

      else if((c>1&&a[i]=='1')||i==n-1)
      {

         s+=(c/(k+1));
         c=1;
      }

   }

   cout<<s<<endl;
}

	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;

	for (int test = 1; test <= t; test++) {
		int n, k;
		cin >> n >> k;
		string s;
		cin >> s;

		int res = 0;

		for (int i = 0; i < n;) {
			int j = i + 1;

			for (; j < n && s[j] != '1'; j++);

			int left = s[i] == '1' ? k : 0;
			int right = j < n && s[j] == '1' ? k : 0;
			int len = j - i;

			if (left == k) {
				len--;
			}

			len -= left + right;

			if (len > 0) {
				res += (len + k) / (k + 1);
			}

			i = j;
		}

		cout << res << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(n<=k+1){
			cout << 1 << nl;
			continue;
		}
		if(v[0]==n){
			ans+=(n-1+k)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			// add k for better ceil()
			if(i==0||i==v.size()-1){
				ans+=((v[i]+k)/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k+k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(v[0]==n){
			ans++;
			ans+=(n-1)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			if(i==0||i==v.size()-1){
				ans+=(v[i]/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(v[0]==n){
			ans+=(n-1+k)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			// add k for better ceil()
			if(i==0||i==v.size()-1){
				ans+=((v[i]+k)/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k+k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(n<k+1){
			cout << 1 << nl;
			continue;
		}
		if(v[0]==n){
			ans+=(n)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			if(i==0){
				ans+=(v[i]/(k+1));
			}else if(i==v.size()-1){
				ans+=(v[i]/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(n<=k+1){
			cout << 1 << nl;
			continue;
		}
		if(v[0]==n){
			ans++;
			ans+=(n-1)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			if(i==0){
				ans+=(v[i]/(k+1));
			}else if(i==v.size()-1){
				ans+=(v[i]/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(v[0]==n){
			ans+=(n+k)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			// add k for better ceil()
			if(i==0||i==v.size()-1){
				ans+=((v[i])/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(n<k+1){
			cout << 1 << nl;
			continue;
		}
		if(v[0]==n){
			ans+=(n)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			if(i==0){
				ans+=(v[i]/(k+1));
			}else if(i==v.size()-1){
				ans+=(v[i]/(k+1));
			}else{
				if(2*k+1<v[i])continue;
				ans+=((v[i]-k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(v[0]==n){
			ans+=(n+k)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			// add k for better ceil()
			if(i==0||i==v.size()-1){
				ans+=((v[i]+k)/(k+1));
			}else{
				if(2*k+1>v[i])continue;
				ans+=((v[i]-k+k)/(k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(v.size()==1){
			ans++;
			ans+=(n-1)/(k+1);
		}else{
			for(int i = 0;i<v.size();i++){
				if(v[i]<=k)continue;
				if(i==0){
					ans+=(v[i]/(k+1));
				}else if(i==v.size()-1){
					ans+=(v[i]/(k+1));
				}else{
					ans+=(v[i]/(2*k+1));
				}
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		for(int i = 0;i<v.size();i++){
			if(i==v.size()-1){
				if(v[i]==n){
					ans++;
					ans+=(n-1)/(k+1);
				}
				continue;
			}
			if(v[i]<=k)continue;
			if(i==0){
				ans++;
				ans+=(v[i]-k-1)/(k+1);
				continue;
			}
			ans+=(v[i])/(2*k+1);
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5+2; // REMEMBER TO CHANGE
const int MOD = 1e9+7;
int t, n, k;
int main(){
	boost();
	cin >> t;
	for(int cnt = 0;cnt<t;cnt++){
		cin >> n >> k;
		string s;
		cin >> s;
		int c = 0, ans = 0;
		vector<int>v;
		for(int i = 0;i<s.size();i++){
			if(s[i]=='0'){
				c++;
			}else{
				v.push_back(c);
				c = 0;
			}
		}
		v.push_back(c);
		if(n<k+1){
			cout << 1 << nl;
			continue;
		}
		if(v[0]==n){
			ans+=(n)/(k+1);
			cout << ans << nl;
			continue;
		}
		for(int i = 0;i<v.size();i++){
			if(v[i]<=k)continue;
			if(i==0){
				ans+=(v[i]/(k+1));
			}else if(i==v.size()-1){
				ans+=(v[i]/(k+1));
			}else{
				ans+=(v[i]/(2*k+1));
			}
		}
		cout << ans << nl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <limits>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <complex>
#include <iomanip>
#include <cassert>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <cstring>
#include <climits>
using namespace std;
#define nl '\n'
#define sp ' '
#define f first
#define s second
#define boost() cin.tie(0); cout.tie(0); cin.sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e5 + 2; // REMEMBER TO CHANGE
const int MOD = 1e9 + 7;
int F[3];
void solve() {
	int n, k, c = 0;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int>v;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			v.push_back(c);
			c = 0;
		} else {
			c++;
		}
	}
	v.push_back(c);
	int ans = 0;
	if (v[0] == n) {
		ans = ((n - 1) / (k + 1))+1;
		cout << ans << nl;
		return;
	}
	for (int i = 0; i < v.size(); i++) {
		if (i == 0 || i == v.size() - 1) {
			ans += v[i] / (k + 1);
		} else {
			if (v[i] < 2 * k + 1) continue;
			ans += (v[i] - k) / (k + 1);
		}
	}
	cout << ans << nl;
}
int main()
{
	boost();
	int t;
	cin >> t;
	for (int g = 0; g < t; g++) {
		solve();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int l=s.length();
queue<int> q;
int count=0;
for (int i=0;i<l;i++){
	if (s[i]=='1')q.push(i);
}
if (q.size()==0){
	s[0]='1';
	q.push(0);
	count++;
}
while (!q.empty()){
	int i =q.front();
	q.pop();
	bool flag1=true;
	bool flag2=true;
	for (int j=1;j<=k&&(i+j)<l;j++){
		if (s[i+j]=='1')flag1=false;
	}
	for (int j=1;j<=k&&(i-j)>=0;j++){
		if(s[i-j]=='1')flag2=false;
	}
	if ((i+k<n)&&flag1==true){
		s[i+k]='1';
		q.push(i+k);
		count++;
	}
	if (i-k>=0&&flag2==true){
		s[i-k]='1';
		q.push(i-k);
		count++;
	}

}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2)count++;
	}
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2)count++;
	}
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int l=s.length();
queue<int> q;
int count=0;
for (int i=0;i<l;i++){
	if (s[i]=='1')q.push(i);
}
if (q.size()==0){
	s[0]='1';
	q.push(0);
	count++;
}
while (!q.empty()){
	int i =q.front();
	q.pop();
	bool flag1=true;
	bool flag2=true;
	for (int j=1;j<=(k+k-1)&&(i+j)<l;j++){
		if (s[i+j]=='1')flag1=false;
	}
	for (int j=1;j<=(k+k-1)&&(i-j)>=0;j++){
		if(s[i-j]=='1')flag2=false;
	}
	if ((i+k<n)&&flag1==true){
		s[i+k]='1';
		q.push(i+k);
		count++;
	}
	if (i-k>=0&&flag2==true){
		s[i-k]='1';
		q.push(i-k);
		count++;
	}

}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0')count++;
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0')count++;
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0'){
		bool flag=true;
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag=false;
				break;
			}
		}
		if(flag)count++;
	}
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0'){
		bool flag=true;
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag=false;
				break;
			}
		}
		if(flag)count++;
	}
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}