/*
 * DATE : 2017-07-07
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/
const int N = 1e5+5;

struct Node {
    int v,x;
    bool operator<(const Node &p) const {
        if(v == p.v) return x < p.x;
        return v < p.v;
    }
};

set<Node> L,R;
map<int,int> Map, Map2;
int a[N],b[N],x[N];
int V[N];
int P[N];
int main()
{
    srand(time(NULL));
    int n;
    in(n);
//    for(int i = 1; i <= n; i ++ ) x[i ] = i;
//    random_shuffle(x + 1, x + n + 1);
//    for(int i = 1;  i <= n; i ++ ) a[i] = x[i] , printf("%d ",a[i]); puts("");
//    random_shuffle(x + 1, x + n + 1);
//    for(int i = 1;  i <= n; i ++ ) b[i] = x[i], printf("%d ",b[i]); puts("") ;

    for(int i = 1;i <= n; i ++ ) in(a[i]);
    for(int i = 1;i <= n; i ++ ) in(b[i]);
    for(int i = 1;i <= n; i ++ ) Map[a[i]] = i;
    for(int i = 1;i <= n; i ++ ) Map2[b[i]] = i;

    for(int i = 1; i <= n;i ++ ) {
        int now = b[i];
        if(i <= Map[now]) L.insert({ Map[now] - i, now}), V[now] = Map[now] - i , P[now] = 0;
        else R.insert({ i - Map[now], now}) , V[now]  = i - Map[now], P[now] = 1;
    }
    int lo = 0, ri = 0;
    int ptr = n;

    for(int i = 1; i <= n; i ++ ) {
//        printf("IN L :\n");
//        for(auto x: L) cout << x.x <<" " << x.v +lo << endl;
//        printf("IN R :\n");
//        for(auto x: R) cout << x.x <<" " << x.v +ri << endl;

        int ans = 1e8;
        if(L.size() ) ans = min( ans, lo + L.begin() -> v );
        if(R.size() ) ans = min( ans, ri + R.begin() -> v );

        vector<int> v;
        for(auto x: L ) {
            if( x.v + lo == 0 ) v.push_back(x.x);
        }
        for(auto x: v ) {
            L.erase({V[x], x});
            R.insert({ -ri , x});
            V[x] = -ri;
            P[x] = 1;
        }
        int last = b[ptr];
        if(P[last] == 1 ) {
            R.erase({ V[last] , last });
            L.insert({ Map[last] - lo , last});
            P[last] = 0;
            V[last] = Map[last] - lo;
        }
        lo--;
        ri++;
        ptr--;
//        int br = 1e8;
//        for(auto x: Map) {
//            br = min(br , abs(x.second - Map2[x.first]));
//        }
        cout << ans <<endl;
//        if(ans != br) assert(0);
//        for(auto& x: Map2) {
//            x.second ++;
//            if(x.second == n + 1) x.second = 1;
//        }

    }

    return 0;
}


// @author peter50216
// Sorry peter50216 I took your code because this problem is really boring
// and if I do not solve it I cannot move in the ladder.
// #includes {{{
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#include<stdarg.h>
#include<time.h>
#include<limits.h>
#include<ctype.h>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
// }}}

int to[101000];
int dif[101000];
int ans[101000];
inline int ABS(int a){return a>0?a:-a;}
int main(){
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        to[a]=i;
    }
    for(i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        dif[i]=to[a]-i;
        ans[i]=101000;
    }
    ans[0]=101000;
    set<int> XD;
    for(i=1;i<=n;i++){
        XD.insert(dif[i]);
        set<int>::iterator it=XD.lower_bound(n-i);
        if(it!=XD.end()){
            ans[i]=min(ans[i],ABS(*it-(n-i)));
        }
        if(it!=XD.begin()){
            it--;
            ans[i]=min(ans[i],ABS(*it-(n-i)));
        }
    }
    XD.clear();
    for(i=n;i>=1;i--){
        XD.insert(dif[i]);
        set<int>::iterator it=XD.lower_bound(-(i-1));
        if(it!=XD.end()){
            ans[i-1]=min(ans[i-1],ABS(*it+(i-1)));
        }
        if(it!=XD.begin()){
            it--;
            ans[i-1]=min(ans[i-1],ABS(*it+(i-1)));
        }
    }
    ans[0]=min(ans[0],ans[n]);
    for(i=0;i<n;i++)printf("%d\n",ans[i]);
}

}


// @author peter50216
// Sorry peter50216 I took your code because this problem is really boring
// and if I do not solve it I cannot move in the ladder.
// #includes {{{
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#include<stdarg.h>
#include<time.h>
#include<limits.h>
#include<ctype.h>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
// }}}

int to[101000];
int dif[101000];
int ans[101000];
inline int ABS(int a){return a>0?a:-a;}
int main(){
    int n,i,j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        to[a]=i;
    }
    for(i=1;i<=n;i++){
        int a;
        scanf("%d",&a);
        dif[i]=to[a]-i;
        ans[i]=101000;
    }
    ans[0]=101000;
    set<int> XD;
    for(i=1;i<=n;i++){
        XD.insert(dif[i]);
        set<int>::iterator it=XD.lower_bound(n-i);
        if(it!=XD.end()){
            ans[i]=min(ans[i],ABS(*it-(n-i)));
        }
        if(it!=XD.begin()){
            it--;
            ans[i]=min(ans[i],ABS(*it-(n-i)));
        }
    }
    XD.clear();
    for(i=n;i>=1;i--){
        XD.insert(dif[i]);
        set<int>::iterator it=XD.lower_bound(-(i-1));
        if(it!=XD.end()){
            ans[i-1]=min(ans[i-1],ABS(*it+(i-1)));
        }
        if(it!=XD.begin()){
            it--;
            ans[i-1]=min(ans[i-1],ABS(*it+(i-1)));
        }
    }
    ans[0]=min(ans[0],ans[n]);
    for(i=0;i<n;i++)printf("%d\n",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define inf 1e8

#define pi pair<ll,ll>
#define pii pair<pi,ll>
#define f first
#define mp make_pair
#define pb push_back
#define s second
#define rep(i,n) for(int i=0;i<n;i++)
#define forup(i,a,b) for(int i=a;i<=b;i++)
int pos1[100011];
int pos2[100011];
int val[100011];
int main(){
	int n;
	cin >> n;
	int a[n],b[2*n];
	rep(i,n)
        cin >> a[i] , a[i]-- , pos1[a[i]]=i;
    rep(i,n)
        cin >> b[i] , b[i]-- , pos2[b[i]]=i;
    set<pi>p1,p2;
    for(int i=0;i<n;i++){
        if(pos1[a[i]]>=pos2[a[i]]){
            p1.insert(make_pair(abs(pos1[a[i]]-pos2[a[i]]),a[i]));
        }
        else{
            p2.insert(make_pair(abs(pos1[a[i]]-pos2[a[i]]),a[i]));
        }
    }
    int ans;
    for(int s=0;s<n;s++){
        ans=n+2;
        ans=min(ans,p1.begin()->first+s+1);
        ans=min(ans,p2.begin()->first-s);
        cout<<ans<<"\n";
        while(p2.size()>0 and (*p2.begin()).first-s-1<=0){
            pi r=*p2.begin();
            p2.erase(r);
            r.f=-s-1;
            p1.insert(r);
        }
        pos2[b[s]]=n+s;
        p2.insert(make_pair(abs(pos1[b[s]]-pos2[b[s]]),b[s]));
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define inf 1e8

#define pi pair<ll,ll>
#define pii pair<pi,ll>
#define f first
#define mp make_pair
#define pb push_back
#define s second
#define rep(i,n) for(int i=0;i<n;i++)
#define forup(i,a,b) for(int i=a;i<=b;i++)
int pos1[100011];
int pos2[100011];
int val[100011];
int main(){
	int n;
	cin >> n;
	int a[n],b[2*n];
	rep(i,n)
        cin >> a[i] , a[i]-- , pos1[a[i]]=i;
    rep(i,n)
        cin >> b[i] , b[i]-- , pos2[b[i]]=i;
    set<pi>p1,p2;
    for(int i=0;i<n;i++){
        if(pos1[a[i]]>=pos2[a[i]]){
            p1.insert(make_pair(abs(pos1[a[i]]-pos2[a[i]]),a[i]));
            val[a[i]]=abs(pos1[a[i]]-pos2[a[i]]);
        }
        else{
            p2.insert(make_pair(abs(pos1[a[i]]-pos2[a[i]]),a[i]));
        }
    }
    int ans;
    for(int s=0;s<n;s++){

        while(p2.size()>0 and (*p2.begin()).first-s<=0){
            pi r=*p2.begin();
            p2.erase(r);
            r.f=-s;
            val[r.s]=r.f;
            p1.insert(r);
        }

        ans=n+2;
        if(p1.size())
        ans=min(ans,p1.begin()->first+s);
        if(p2.size())
        ans=min(ans,p2.begin()->first-s);
        cout<<ans<<"\n";

        pos2[b[s]]=n-1;

        p2.insert(make_pair(s+1+abs(pos1[b[s]]-pos2[b[s]]),b[s]));
        p1.erase(make_pair( val[b[s]] , b[s] ));

    }
}


#include <bits/stdc++.h>

#define db 	cout << "*****" << endl;
#define Max 100009
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mk make_pair
#define MOD 1000000007

using namespace std;

int n,a;
int arr[Max];
bool vis[Max];
int jog[Max];

int main(){

	cin >> n;
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		arr[a]=i;
	}
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		int dist=0;

		if( arr[a] <= i )	dist = n - i + arr[a];
		else 				dist = arr[a] - i ;

		vis[dist] = 1 ;

	}
	int poi=n;

	for( int i=n-1;i>=0;i--){
		poi++;
		if( vis[i] ) poi=0;
		jog[i] = poi;
	}

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

		poi++;
		if( vis[i] ) poi=0;
		cout << min(poi,jog[i] ) << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define db 	cout << "*****" << endl;
#define Max 100009
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mk make_pair
#define MOD 1000000007

using namespace std;

int n,a;
int arr[Max];
bool vis[Max];
int jog[Max];

int main(){

	cin >> n;
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		arr[a]=i;
	}
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		int dist=0;

		if( arr[a] < i )	dist = n - i + arr[a];
		else 				dist = arr[a] - i ;

		vis[dist] = 1 ;

	}
	int poi=n;

	for( int i=n-1;i>=0;i--){
		poi++;
		if( vis[i] ) poi=0;
		jog[i] = poi;
	}

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

		poi++;
		if( vis[i] ) poi=0;
		cout << min(poi,jog[i] ) << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define db 	cout << "*****" << endl;
#define Max 500009
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mk make_pair
#define MOD 1000000007

using namespace std;

int n;
pair < pair < int , int > , int  > arr[Max];

map < int , int > mapp;
vector < int > v;

int seg[Max*4];

int find( int l , int r , int id , int ll , int rr ){
	if( ll <= l && r <= rr )return seg[id];
	if( l > rr || r < ll  ) return 0;

	int mid = ( l + r ) / 2 ;
	return max(find( l , mid , id * 2 , ll , rr ) , find( mid+1 , r , id*2+1 , ll , rr) );
}
void upd( int l , int r , int id , int nd , int val ){

	if( l == r ){
		seg[id] = max( seg[id] , val);
		return ;
	}
	int mid = (l+r)/2;
	if( nd <= mid ) upd( l , mid , id * 2 , nd , val );
	else 		 upd(mid+1 , r  , id * 2+1 , nd , val );

	seg[id] = max( seg[id*2] , seg[id*2+1]);

}
int main(){

	cin >> n;

	for( int i=0;i<n;i++)scanf("%d" ,&arr[i].ff.ff);
	for( int i=0;i<n;i++)scanf("%d" ,&arr[i].ff.ss);
	for( int i=0;i<n;i++)scanf("%d" ,&arr[i].ss);

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

		int a = arr[i].ff.ss;
		if( mapp[a] == 0  ){
			mapp[a]=1;
			v.pb(a);
		}
	}
	sort(v.begin(),v.end());
	int sz=v.size();

	int poi=1;
	for( int i=0;i<sz;i++){
		if( i != 0 && v[i-1] == v[i])
			continue;
		mapp[v[i]]=poi++;
	}
	poi--;
	sort( arr , arr + n );

	int ans=0;

	for( int i=n-1;i>=0;i--){

		int j=i;

		while( arr[i].ff.ff == arr[j].ff.ff && j >= 0 ){
			int ma = find( 1 , poi , 1 , mapp[arr[j].ff.ss]+1 , poi );

			if( ma > arr[j].ss )ans++;

			j--;
		}
		for( int k=j+1;k<=i;k++)
			upd( 1 , poi , 1 , mapp[arr[k].ff.ss] , arr[k].ss);
		i=j+1;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define db 	cout << "*****" << endl;
#define Max 100009
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mk make_pair
#define MOD 1000000007

using namespace std;

int n,a;
int arr[Max];
bool vis[Max];
int jog[Max];

int main(){

	cin >> n;
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		arr[a]=i;
	}
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		int dist=0;

		if( arr[a] < i )	dist = n - i + arr[a];
		else 				dist = arr[a] - i ;

		vis[dist] = 1 ;
		vis[dist+n] = 1 ;

	}
	int poi=n;

	for( int i=2*n-1;i>=0;i--){
		poi++;
		if( vis[i] ) poi=0;
		jog[i] = poi;
	}

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

		poi++;
		if( vis[i] ) poi=0;
		cout << min(poi,jog[i] ) << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

#define db 	cout << "*****" << endl;
#define Max 500009
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define mk make_pair
#define MOD 1000000007

using namespace std;

int n,a;
int arr[Max];
bool vis[Max];
int jog[Max];

vector < pair < int , int > > rtol[Max];
vector < pair < int , int > > ltor[Max];

vector < int > vr[Max];
vector < int > vl[Max];

multiset < int > sr;
multiset < int > sl;

int ans[Max];

int main(){

	cin >> n;
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);
		arr[a]=i;
		ans[i]=2*n;
	}
	for( int i=1;i<=n;i++){
		scanf("%d" , &a);

		if( arr[a] > i ){

			int zr = i + n - arr[a] + 1 ;
			int yap = i;

			rtol[zr].pb({zr,yap});

			ltor[0].pb({ zr - n , yap+1});
			ltor[zr].pb({ zr , n+1 });

		}else{

			int zr =  i - arr[a] + 1 ;
			int yap = i;

			rtol[n+1].pb({n+zr,yap});
			rtol[zr].pb({zr,0});
			ltor[zr].pb({zr,yap+1});
		}
	}

	for( int i=0;i<(int)rtol[n+1].size();i++){

		int a = rtol[n+1][i].ff;
		int b = rtol[n+1][i].ss;
		sr.insert(a);
		vr[b].pb(a);
	}

	for( int i=n;i>=1;i--){

		for( int j=0;j<int(vr[i].size());j++) 	sr.erase(sr.find(vr[i][j]));
		for( int j=0;j<int(rtol[i].size());j++){
			sr.insert(rtol[i][j].ff);
			vr[rtol[i][j].ss].pb(rtol[i][j].ff);
		}

		int ll = *sr.lower_bound(i);
		if( ll - i < ans[i] )ans[i]= ll - i ;
	}
	for( int i=0;i<(int)ltor[0].size();i++){

		int a = ltor[0][i].ff;
		int b = ltor[0][i].ss;
		sl.insert(a);
		vl[b].pb(a);
	}

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

		for( int j=0;j<int(vl[i].size());j++) 	sl.erase(sl.find(vl[i][j]));

		for( int j=0;j<int(ltor[i].size());j++){
			sl.insert(ltor[i][j].ff);
			vl[ltor[i][j].ss].pb(ltor[i][j].ff);
		}

		int rr = *--sl.upper_bound(i);
		if( abs(rr - i) < ans[i] )ans[i]= abs(rr - i) ;
	}

	for( int i=1;i<=n;i++)printf("%d\n" ,ans[i] );

	return 0;
}
/*
10
5 1 6 2 8 3 4 10 9 7
3 1 10 6 8 5 2 7 9 4
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

int a[N], b[N], p[N], n;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    p[--a[i]] = i;
  }
  multiset<int> l, r;
  for (int i = 0; i < n; ++i) {
    scanf("%d", b + i);
    b[i]--;
    l.insert(p[b[i]] - i);
  }
  int ld = 0, rd = n;
  for (int i = 0; i < n; ++i) {
    multiset<int>::iterator it;
    int ret = n;
    if (l.size()) {
      it = l.lower_bound(-ld);
      if (it != l.end()) ret = min(ret, abs(*it + ld));
      if (it != l.begin()) ret = min(ret, abs(*(--it) + ld));
    }
    if (r.size()) {
      it = r.lower_bound(rd);
      if (it != r.end()) ret = min(ret, abs(*it - rd));
      if (it != r.begin()) ret = min(ret, abs(*(--it) - rd));
    }
    l.erase(l.find(p[b[i]] - i));
    r.insert(p[b[i]] - i);
    ld++, rd--;
    printf("%d\n", ret);
  }
  return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

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

const int N = 1e5 + 5;

int n;
int a[N], b[N], dp[N];
vector < int > add1[N], del1[N], add2[N], del2[N];

void min1(int l, int r, int k) {
    if(l <= r) {
        add1[l].push_back(k + l);
        del1[r].push_back(k + l);
    }
}

void min2(int l, int r, int k) {
    if(l <= r) {
        add2[l].push_back(k - r);
        del2[r].push_back(k - r);
    }
}

int main () {

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        a[x] = i;
    }

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        b[x] = i;
    }

    multiset < int > s;

    for(int i = 1; i <= n; i++) {
        int x = a[i], y = b[i];
        if(y > x) {
            int dist = y - x;
            min1(1, dist + 1, dist);
            min2(dist + 2, b[i], a[i] - 1);
            min1(b[i] + 1, n, n - a[i]);
        }
        else {
            min2(1, b[i], a[i] - 1);
            min1(b[i] + 1, b[i] + n - a[i] + 1, n - a[i]);
            min2(b[i] + n - a[i] + 2, n, a[i] - b[i] - 1);        }
    }

    memset(dp, 63, sizeof(dp));

    {
        multiset < int > s;
        for(int i = 1; i <= n; i++) {
            foreach(it, add1[i])
                s.insert(*it);
            if(s.size())
            dp[i] = min(dp[i], *s.begin() - i);
            foreach(it, del1[i])
                s.erase(s.find(*it));
        }
    }

    {
        multiset < int > s;
        for(int i = 1; i <= n; i++) {
            foreach(it, add2[i])
                s.insert(*it);
            if(s.size())
                dp[i] = min(dp[i], *s.begin() + i);
            foreach(it, del2[i])
                s.erase(s.find(*it));
        }
    }

    for(int i = 1; i <= n; i++)
        printf("%d\n", dp[i]);

    return 0;

}


#include "bits/stdc++.h"

using namespace std;

#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

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

const int N = 2e5 + 5;

int n;
int a[N], b1[N], b2[N], dp[N];

int main () {

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        a[x] = i;
    }

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        b1[x] = i;
        b2[x] = i + n;
    }

    memset(dp, 63, sizeof(dp));

    for(int i = 1; i <= n; i++) {
        dp[abs(a[i] - b1[i]) + 1] = 0;
        dp[abs(a[i] - b2[i]) + 1] = 0;
    }

    for(int i = 2; i <= n; i++)
        dp[i] = min(dp[i], dp[i - 1] + 1);

    for(int i = n - 1; i >= 1; i--)
        dp[i] = min(dp[i], dp[i + 1] + 1);

    for(int i = 1; i <= n; i++)
        printf("%d\n", dp[i]);

    return 0;

}


#include "bits/stdc++.h"

using namespace std;

#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

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

const int N = 2e5 + 5;

int n;
int a[N], b1[N], b2[N], dp[N];

int main () {

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        a[x] = i;
    }

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        b1[x] = i;
        b2[x] = i + n;
    }

    memset(dp, 63, sizeof(dp));

    for(int i = 1; i <= n; i++) {
        dp[abs(a[i] - b1[i]) + 1] = 0;
        dp[abs(a[i] - b2[i]) + 1] = 0;
    }

    for(int i = 2; i < N; i++)
        dp[i] = min(dp[i], dp[i - 1] + 1);

    for(int i = N - 1; i >= 1; i--)
        dp[i] = min(dp[i], dp[i + 1] + 1);

    for(int i = 1; i <= n; i++)
        printf("%d\n", dp[i]);

    return 0;

}


#include "bits/stdc++.h"

using namespace std;

#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); it++)

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

const int N = 1e5 + 5;

int n;
int a[N], b[N], dp[N];
vector < int > add1[N], del1[N], add2[N], del2[N];

void min1(int l, int r, int k) {
    if(l <= r) {
        add1[l].push_back(k + l);
        del1[r].push_back(k + l);
    }
}

void min2(int l, int r, int k) {
    if(l <= r) {
        add2[l].push_back(k - r);
        del2[r].push_back(k - r);
    }
}

int main () {

    scanf("%d", &n);

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        a[x] = i;
    }

    for(int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        b[x] = i;
    }

    multiset < int > s;

    for(int i = 1; i <= n; i++) {
        int x = a[i], y = b[i];
        if(y > x) {
            int dist = y - x;
            min1(1, dist + 1, dist);
            min2(dist + 2, b[i], a[i] - 1);
            min1(b[i] + 1, n, n - a[i]);
        }
        else {
            min2(1, b[i], a[i] - 1);
            min1(b[i] + 1, b[i] + n - a[i] + 1, n - a[i]);
            min2(b[i] + n - a[i] + 2, n, a[i] - b[i] - 1);
        }
    }

    memset(dp, 63, sizeof(dp));

    {
        multiset < int > s;
        for(int i = 1; i <= n; i++) {
            foreach(it, add1[i])
                s.insert(*it);
            if(s.size())
            dp[i] = min(dp[i], *s.begin() - i);
            foreach(it, del1[i])
                s.erase(s.find(*it));
        }
    }

    {
        multiset < int > s;
        for(int i = 1; i <= n; i++) {
            foreach(it, add2[i])
                s.insert(*it);
            if(s.size())
                dp[i] = min(dp[i], *s.begin() + i);
            foreach(it, del2[i])
                s.erase(s.find(*it));
        }
    }

    for(int i = 1; i <= n; i++)
        printf("%d\n", dp[i]);

    return 0;

}


#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int INF = 2e9;

int ps[N], res[N];
queue <int> q;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist = ps[x] - i;
        if (dist < 0) {
            dist += n;
        }
        res[dist] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int pred = x - 1;
        if (x < 0) {
            x += n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
        pred = x + 1;
        if (x == n) {
            x -= n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int INF = 2e9;

int ps[N], res[N];
queue <int> q;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist = ps[x] - i;
        if (dist < 0) {
            dist += n;
        }
        res[dist] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int pred = x - 1;
        if (pred < 0) {
            pred += n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
        pred = x + 1;
        if (pred == n) {
            pred -= n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


#include <iostream>

using namespace std;
const int N = 1e5 + 10;
const int INF = 2e9;

int pos[N];
int len[N];
int ps[N];
int res[N];
int up[N];
int down[N];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist;
        if (ps[x] <= i) {
            dist = i - ps[x];
        } else {
            dist = i - ps[x] + n;
        }
        res[dist] = 0;
        up[dist] = max(up[dist], n - ps[x] - 1);
        down[dist] = max(down[dist], ps[x]);
    }
    int size = 0;
    for (int i = 0; i < 2 * n; i++) {
        while (size > 0 && i - pos[size] > len[size]) {
            size--;
        }
        if (size != 0) {
            res[i % n] = min(res[i % n], i - pos[size]);
        }
        if (i < n) {
            size++;
            pos[size] = i;
            len[size] = down[i];
        }
    }
    size = 0;
    for (int i = n - 1; i > -n; i--) {
        while (size > 0 && pos[size] - i > len[size]) {
            size--;
        }
        if (size != 0) {
            res[(i + n) % n] = min(res[(i + n) % n], pos[size] - i);
        }
        if (i >= 0) {
            size++;
            pos[size] = i;
            len[size] = up[i];
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int INF = 2e9;

int ps[N], res[N];
queue <int> q;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist = ps[x] - i;
        if (dist < 0) {
            dist += n;
        }
        res[dist] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int pred = x - 1;
        if (x < 0) {
            x += n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
        pred = x + 1;
        if (x == n) {
            x -= n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
    }
    for (int i = 0; i < n; i++) {
        printf("%d\n", res[i]);
    }
    return 0;
}


#include <iostream>
#include <queue>

using namespace std;
const int N = 1e5 + 10;
const int INF = 2e9;

int ps[N], res[N];
queue<int> q;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist;
        if (ps[x] <= i) {
            dist = i - ps[x];
        } else {
            dist = i - ps[x] + n;
        }
        res[dist] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int pred = x - 1;
        if (pred < 0) {
            pred += n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
        pred = x + 1;
        if (pred == n) {
            pred -= n;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


#include <iostream>
#include <queue>

using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
const int INF = 2e9;

int ps[N], res[N];
queue<int> q;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        ps[x] = i;
    }
    for (int i = 0; i < n; i++) {
        res[i] = INF;
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        int dist;
        if (ps[x] <= i) {
            dist = i - ps[x];
        } else {
            dist = i - ps[x] + n;
        }
        res[dist] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (res[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        int pred = x - 1;
        if (pred < 0) {
            pred = x;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
        pred = x + 1;
        if (pred == n) {
            pred = x;
        }
        if (res[x] + 1 < res[pred]) {
            res[pred] = res[x] + 1;
            q.push(pred);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << res[i] << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long INT;

#define NN 100010

int A[NN], B[NN];
int pos_A[NN], pos_B[NN];

multiset<int> st;

int solve(int s) {
	auto it = st.upper_bound(-s);
	int ans = NN;
	if(it != st.end()) ans = min(ans, abs(*it + s));
	if(it == st.begin()) return ans;
	it--;
	ans = min(ans, abs(*it+s));
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);

	for(int i=1; i<=n; i++) scanf("%d", A+i), pos_A[A[i]] = i;
	for(int i=1; i<=n; i++) scanf("%d", B+i), pos_B[B[i]] = i;

	for(int i=1; i<=n; i++) st.insert(pos_A[i] - pos_B[i]);

	printf("%d\n", solve(0));

	for(int i=1; i<n; i++) {
		int u = B[i];
		int val = pos_A[u] - pos_B[u];
		st.erase(st.find(val));
		st.insert(pos_A[u] - n - i);
		printf("%d\n", solve(i));
	}

}


#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back

using namespace std;

typedef long long INT;
typedef vector<int> VI;
typedef pair<int, int> pii;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}
template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}
int power(int a, int b, int m, int ans=1){for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m; return ans;}

#define NN 100100
int a[NN], p[NN], b[NN];
set <pii> s;

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n;
	cin >> n;
	for(int i=0; i<n; i++) gn(a[i]), p[a[i]]=i;
	for(int i=0; i<n; i++) gn(b[i]), s.insert(pii(i-p[b[i]], b[i]));

	for(int i=0; i<n; i++){
		int mn=n-1;
		auto it=s.lower_bound(pii(i, 0));
		if(it!=s.end()) smin(mn, it->x-i);
		if(it!=s.begin()) it--, smin(mn, i-it->x);
		printf("%d\n", mn);
		s.erase(pii(i-p[b[i]], b[i]));
		s.insert(pii(i+n-p[b[i]], b[i]));
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long INT;

#define NN 100010

int A[NN], B[NN];
int pos_A[NN], pos_B[NN];

multiset<int> st;

int solve(int s) {
	auto it = st.upper_bound(-s);
	int ans = NN;
	if(it != st.end()) ans = min(ans, abs(*it + s));
	it--;
	if(it != st.begin()) ans = min(ans, abs(*it+s));
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n;
	scanf("%d", &n);

	for(int i=1; i<=n; i++) scanf("%d", A+i), pos_A[A[i]] = i;
	for(int i=1; i<=n; i++) scanf("%d", B+i), pos_B[B[i]] = i;

	for(int i=1; i<=n; i++) st.insert(pos_A[i] - pos_B[i]);

	printf("%d\n", solve(0));

	for(int i=1; i<n; i++) {
		int u = B[i];
		int val = pos_A[u] - pos_B[u];
		st.erase(st.find(val));
		st.insert(pos_A[u] - n - i);
		printf("%d\n", solve(i));
	}

}


#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define inf 0x3f3f3f3f

using namespace std;

typedef double DO;
typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;
typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}
template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}
int power(int a, int b, int m, int ans=1) {for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;return ans;}
#define NN 100011
int a[NN], b[NN], pos[NN];
multiset<int> s;

void solve() {
	int n; gn(n);
	for(int i=1; i<=n; i++) gn(a[i]), pos[a[i]] = i;
	s.insert(inf); s.insert(-inf);
	for(int i=1; i<=n; i++) {
		gn(b[i]);
		s.insert(i-pos[b[i]]);
	}
	for(int i=0; i<n; i++) {
		print(min((*s.lower_bound(i))-i, i-(*--s.lower_bound(i))));
		puts("");
		s.erase(s.find(i+1-pos[b[i+1]]));
		s.insert(i+1-pos[b[i+1]]+n);
	}
}

int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	solve();
	return 0;
}


#include <iostream>
using namespace std;
int n, a[100042], b[100042], onInd[1000042];
int k = 17;
struct v {
    int minV, sV;
}it[2][1000042];
int gt( int t ) {
    return t == 1 ? 1 : -1;
}
void handle ( int ind, int s, int t ) {
    it[t][ind].minV = min( it[t][ind].minV, it[t][ind].sV );
    it[t][ind].minV = min( it[t][ind].minV, it[t][ind].sV+s*gt(t) );
    if ( s > 1 ) {
        it[t][ind*2  ].sV = min( it[t][ind*2  ].sV, it[t][ind].sV );
        it[t][ind*2+1].sV = min( it[t][ind*2+1].sV, it[t][ind].sV+gt(t)*s/2 );
    }
}

void add ( int s, int f, int ss, int ff, int ind, int v, int t ) {
    handle( ind, f-s, t );
    if ( f <= ss || ff <= s ) { return ; }
    if ( ss <= s && f <= ff ) {
        it[t][ind].sV = min( v+gt(t)*(s-ss), it[t][ind].sV );
        it[t][ind].minV = min( it[t][ind].sV, it[t][ind].minV );
        it[t][ind].minV = min( it[t][ind].sV+gt(t)*(f-s), it[t][ind].minV );
        return;
    }
    add ( s, (s+f)/2, ss, ff, ind*2, v, t );
    add ((s+f)/2, f, ss, ff, ind*2+1, v, t );
    it[t][ind].minV = min( it[t][ind*2].minV, it[t][ind*2+1].minV );
}
void handleAll ( int s, int f, int ind, int t ) {
    handle ( ind, f-s, t );
    if ( f-s == 1 ) { return; }
    handleAll( s, (s+f)/2, ind*2  , t );
    handleAll( (s+f)/2, f, ind*2+1, t );
}
int sum[1000042];
int main () {
    for ( int i = 0 ; i < (1<<k+1) ; i ++ ) {
        it[0][i].minV = 1<<20;
        it[0][i].sV = 1<<20;
        it[1][i].minV = 1<<20;
        it[1][i].sV = 1<<20;
    }
    cin >> n ;
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
        onInd [ a[i] ] = i;
    }
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> b[i];
        int i1 = i, i2 = onInd[ b[i] ];
        if ( i1 >= i2 ) {
            add ( 0, (1<<k), 0         , n-i1      , 1, i1-i2          , 1  );
            add ( 0, (1<<k), n-i1      , n-i1+1+i2 , 1, i2+1           , 0 );
            add ( 0, (1<<k), n-i1+i2+1 , n         , 1, 1              , 1  );
        }else {
            add ( 0, (1<<k), 0        ,i2-i1,  1,   i2-i1+1,   0);
            add ( 0, (1<<k), i2-i1    ,n-i1  , 1,         0,   1);
            add ( 0, (1<<k), n-i1     , n,  1, i2+1, 0  );
        }
    }

    handleAll( 0, (1<<k), 1, 0 );
    handleAll( 0, (1<<k), 1, 1 );

    for ( int j = 0 ; j < n ; j ++ ) {
        cout << min( it[0][(1<<k)+j].minV, it[1][(1<<k)+j].minV ) << " ";
    }
    cout << "\n";

    return 0;
}
/*
    i1
            i2

n-i2 -> +
i1+n-i2  -> -

*/


#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100042], b[100042], onInd[1000042];
int k = 17;
struct v {
    int minV, sV;
}it[2][1000042];
int gt( int t ) {
    return t == 1 ? 1 : -1;
}
void handle ( int ind, int s, int t ) {
    it[t][ind].minV = min( it[t][ind].minV, it[t][ind].sV );
    it[t][ind].minV = min( it[t][ind].minV, it[t][ind].sV+s*gt(t) );
    if ( s > 1 ) {
        it[t][ind*2  ].sV = min( it[t][ind*2  ].sV, it[t][ind].sV );
        it[t][ind*2+1].sV = min( it[t][ind*2+1].sV, it[t][ind].sV+gt(t)*s/2 );
    }
}

void add ( int s, int f, int ss, int ff, int ind, int v, int t ) {
    handle( ind, f-s, t );
    if ( f <= ss || ff <= s ) { return ; }
    if ( ss <= s && f <= ff ) {
        it[t][ind].sV = min( v+gt(t)*(s-ss), it[t][ind].sV );
        it[t][ind].minV = min( it[t][ind].sV, it[t][ind].minV );
        it[t][ind].minV = min( it[t][ind].sV+gt(t)*(f-s), it[t][ind].minV );
        return;
    }
    add ( s, (s+f)/2, ss, ff, ind*2, v, t );
    add ((s+f)/2, f, ss, ff, ind*2+1, v, t );
    it[t][ind].minV = min( it[t][ind*2].minV, it[t][ind*2+1].minV );
}
void handleAll ( int s, int f, int ind, int t ) {
    handle ( ind, f-s, t );
    if ( f-s == 1 ) { return; }
    handleAll( s, (s+f)/2, ind*2  , t );
    handleAll( (s+f)/2, f, ind*2+1, t );
}
int sum[1000042];
int main () {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    for ( int i = 0 ; i < (1<<k+1) ; i ++ ) {
        it[0][i].minV = 1<<20;
        it[0][i].sV = 1<<20;
        it[1][i].minV = 1<<20;
        it[1][i].sV = 1<<20;
    }
    cin >> n ;
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
    }
    reverse( a, a+n );
    for ( int i = 0 ; i < n ; i ++ ) {
        cin >> b[i];
        onInd [ a[i] ] = i;
    }
    reverse( b, b+n );

    for ( int i = 0 ; i < n ; i ++ ) {
        int i1 = i, i2 = onInd[ b[i] ];

        if ( i1 >= i2 ) {
            add ( 0, (1<<k), 0         , n-i1      , 1, i1-i2          , 1  );
            add ( 0, (1<<k), n-i1      , n-i1+1+i2 , 1, i2+1           , 0 );
            add ( 0, (1<<k), n-i1+i2+1 , n         , 1, 1              , 1  );
        }else {
            add ( 0, (1<<k), 0        ,i2-i1,  1,   i2-i1+1,   0);
            add ( 0, (1<<k), i2-i1    ,n-i1  , 1,         0,   1);
            add ( 0, (1<<k), n-i1     , n,  1, i2+1, 0  );
        }

    }
    handleAll( 0, (1<<k), 1, 0 );
    handleAll( 0, (1<<k), 1, 1 );

    for ( int j = 0 ; j < n ; j ++ ) {
        cout << min( it[0][(1<<k)+j].minV, it[1][(1<<k)+j].minV ) << "\n";
    }

    return 0;
}
/*
10
5 1 6  2 8 3 4 10 9 7
3 1 10 6 8 5 2  7 9 4

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

public class Solution
{

    public static int gcd(int a,int b){
        if(a==1 ||b==1)
        return 1;
        if(b==0)
        return a;
        return gcd(b, a%b);
    }
    public static void main(String[] args) throws IOException
    {

       BufferedReader br = new BufferedReader(
                              new InputStreamReader(System.in));
         StringBuilder out=new StringBuilder();
        StringTokenizer  st=new StringTokenizer(br.readLine());
          int t=Integer.parseInt(st.nextToken());

		while(t-->0){
		  st=new StringTokenizer(br.readLine());
		 int n=Integer.parseInt(st.nextToken());
 int r=Integer.parseInt(st.nextToken());

          		  st=new StringTokenizer(br.readLine());

		  HashSet<Integer> h=new HashSet<>();

   for(int i=0;i<n;i++)h.add(Integer.parseInt(st.nextToken()));
    Integer[] a=new Integer[h.size()];int k=0;
    for(int i:h)a[k++]=i;
      Arrays.sort(a,Collections.reverseOrder());
      int c=0,i,j;
      for( i=0;i<n;i++){
              if(a[i]-(c*r)>0){
                  c++;
              }
          else{
              break;
          }

      }

              out.append(c+"\n");
		}
		System.out.println(out);

}}
// class Graph
// {
//     private int V;   // No. of vertices

//     // Array  of lists for Adjacency List Representation
//      LinkedList<Integer> adj[];

//     // Constructor
//     Graph(int v)
//     {
//         V = v;
//         adj = new LinkedList[v];
//         for (int i=0; i<v; ++i)
//             adj[i] = new LinkedList();
//     }

//     //Function to add an edge into the graph
//     void addEdge(int v, int w)
//     {
//         adj[v].add(w);
//         adj[w].add(v);// Add w to v's list.
//     }

//     // A function used by DFS
// }


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package problema1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Problema1 {
    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static void main(String[] args) {
        // TODO code application logic here
        // q = queries; n = monsters; r = radio empuje
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            int n = in.nextInt();
            int r = in.nextInt();
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            //Leer Posiciones
            for(int j=0;j<n;j++)
            {
                int entrada = in.nextInt();
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Monstruos.sort(Comparator.reverseOrder());
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
            /*
            for(Monster mons : MonstruosVoladores)
            {
                System.out.println(mons.posicion);
            }
            */
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
            }
            recorrido += desplazar;
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion) {
        super(posicion);
    }

}


import java.util.Arrays;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            TreeSet <Monster> Monstruos = new TreeSet();
            TreeSet <FlyingMonster> MonstruosVoladores = new TreeSet();
            boolean existe_0 = false;
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if((entrada == 0) & (!existe_0))
                {
                    MonstruosVoladores.add(new FlyingMonster(0));
                    existe_0 = true;
                }
                if(entrada > 0)
                {
                    Monstruos.add(new Monster(entrada));
                }
                else
                {
                    MonstruosVoladores.add(new FlyingMonster(entrada));
                }
            }
            Monstruos = (TreeSet<Monster>)Monstruos.descendingSet();
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(TreeSet <Monster> Mons, TreeSet <FlyingMonster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        int killed = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
                recorrido += desplazar;
                killed++;
            }
            else
            {
                break;
            }
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


import java.util.Arrays;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            TreeSet <Monster> Monstruos = new TreeSet();
            TreeSet <FlyingMonster> MonstruosVoladores = new TreeSet();
            boolean existe_0 = false;
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if((entrada == 0) & (!existe_0))
                {
                    MonstruosVoladores.add(new FlyingMonster(0));
                    existe_0 = true;
                }
                if(entrada > 0)
                {
                    Monstruos.add(new Monster(entrada));
                }
                else
                {
                    MonstruosVoladores.add(new FlyingMonster(entrada));
                }
            }
            Monstruos = (TreeSet<Monster>)Monstruos.descendingSet();
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(TreeSet <Monster> Mons, TreeSet <FlyingMonster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        int killed = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
                recorrido += desplazar;
                killed++;
            }
            else
            {
                break;
            }
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            boolean existe_0 = false;
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if((entrada == 0) & (!existe_0))
                {
                    MonstruosVoladores.add(new FlyingMonster(0));
                    existe_0 = true;
                }
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Collections.sort(Monstruos);
            Collections.reverse(Monstruos);
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        int killed = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
                recorrido += desplazar;
                killed++;
            }
            else
            {
                break;
            }
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


package problema1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Problema1 {
    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static void main(String[] args) {
        // q = queries; n = monsters; r = radio empuje
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            int n = in.nextInt();
            int r = in.nextInt();
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            //Leer Posiciones
            for(int j=0;j<n;j++)
            {
                int entrada = in.nextInt();
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Monstruos.sort(Comparator.reverseOrder());
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
            }
            recorrido += desplazar;
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion) {
        super(posicion);
    }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Monstruos.sort(Comparator.reverseOrder());
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
            }
            recorrido += desplazar;
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


import java.util.Arrays;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            TreeSet <Monster> Monstruos = new TreeSet();
            TreeSet <FlyingMonster> MonstruosVoladores = new TreeSet();
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if(entrada > 0)
                {
                    Monstruos.add(new Monster(entrada));
                }
                else
                {
                    MonstruosVoladores.add(new FlyingMonster(entrada));
                }
            }
            Monstruos = (TreeSet<Monster>)Monstruos.descendingSet();
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static int min_moves(TreeSet <Monster> Mons, TreeSet <FlyingMonster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        int killed = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
                recorrido += desplazar;
                killed++;
            }
            else
            {
                break;
            }
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        // q = queries; n = monsters; r = radio empuje
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int q = Integer.parseInt(br.readLine());
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int r = Integer.parseInt(st.nextToken());
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            boolean existe_0 = false;
            //Leer Posiciones
            st = new StringTokenizer(br.readLine());
            for(int j=0;j<n;j++)
            {
                int entrada = Integer.parseInt(st.nextToken());
                if((entrada == 0) & (!existe_0))
                {
                    MonstruosVoladores.add(new FlyingMonster(0));
                    existe_0 = true;
                }
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Monstruos.sort(Comparator.reverseOrder());
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        int killed = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
                recorrido += desplazar;
                killed++;
            }
            else
            {
                break;
            }
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion)
    {
        super(posicion);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author axela
 */
public class Main {

    public static void main(String[] args) {
        // q = queries; n = monsters; r = radio empuje
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        int tiros[] = new int[q];
        for(int i=0;i<q;i++)
        {
            int n = in.nextInt();
            int r = in.nextInt();
            int[] arreglo_pos = new int[n];
            List <Monster> Monstruos = new ArrayList<>();
            List <Monster> MonstruosVoladores = new ArrayList<>();
            //Leer Posiciones
            for(int j=0;j<n;j++)
            {
                int entrada = in.nextInt();
                if(!contains(arreglo_pos,entrada))
                {
                    arreglo_pos[j] = entrada;
                    if(entrada > 0)
                    {
                        Monstruos.add(new Monster(entrada));
                    }
                    else
                    {
                        MonstruosVoladores.add(new FlyingMonster(entrada));
                    }
                }
            }
            Monstruos.sort(Comparator.reverseOrder());
            tiros[i] = min_moves(Monstruos, MonstruosVoladores, r);
        }
        for (int i : tiros)
        {
            System.out.println(i);
        }
    }

    public static boolean contains(final int[] arr, final int key)
    {
        return Arrays.stream(arr).anyMatch(i -> i == key);
    }

    public static int min_moves(List <Monster> Mons, List <Monster> FlyMons, int desplazar)
    {
        int moves = 0;
        int recorrido = 0;
        moves += FlyMons.size(); //Todos los monstruos requieren de 1 disparo cada 1, no hay repetidos, es irrelevante su posicion
        for (Monster monstruo : Mons)
        {
            if(monstruo.posicion - recorrido > 0)
            {
                moves++;
            }
            recorrido += desplazar;
        }
        return moves;
    }

}
class Monster implements Comparable<Monster>
{
    public int posicion;
    //Constructor
    public Monster(int posicion)
    {
        this.posicion = posicion;
    }
    @Override
    public int compareTo(Monster OtroMons)
    {
       return this.posicion-OtroMons.posicion;
    }
}
class FlyingMonster extends Monster
{
    public FlyingMonster(int posicion) {
        super(posicion);
    }

}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=k;
            int count=1;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=k;
            int count=1;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    --j;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            int k=sc.nextInt();
            int array[]=new int[n+1];
            for(int j=1;j<=n;j++){
                 array[j]=sc.nextInt();

            }
            if(n==1){
                System.out.println(1);
                continue;
            }else{

            Arrays.sort(array);
            int j=n;
            int freq=0;
            int count=0;
            while(j>=1){
                if(array[j]==array[j-1]){
                    --j;
                }
                else{
                    if(array[j]<=freq){
                        break;
                    }else{
                        ++count;
                        freq+=k;
                        --j;
                    }

                }
            }
            System.out.println(count);
            }
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args)throws IOException {
        Scanner sc=new Scanner(System.in);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0L;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            out.println(count);
        }
        out.flush();
    	out.close();
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args)throws IOException {
        BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int q=Integer.parseInt(sc.readLine());
        for(int i=0;i<q;i++){
            int n=Integer.parseInt(sc.readLine());
            Long k=Long.parseLong(sc.readLine());
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=Integer.parseInt(sc.readLine());;
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0L;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=k;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0L;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            int k=sc.nextInt();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }

            Collections.sort(array);
            int j=array.size()-2;
            int freq=k;
            int count=1;
            while(j>=0){
                if(array.get(j)-freq>0){
                    freq+=k;
                    --j;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args)throws IOException {
        Scanner sc=new Scanner(System.in);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0L;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            out.println(count);
        }
        out.flush();
    	out.close();
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            int k=sc.nextInt();
            int array[]=new int[n+1];
            for(int j=1;j<=n;j++){
                 array[j]=sc.nextInt();

            }
            if(n==1){
                System.out.println(1);
                continue;
            }
            Arrays.sort(array);
            int j=n;
            int freq=0;
            int count=0;
            while(j>=1){
                if(array[j]==array[j-1]){
                    --j;
                }
                else{
                    if(array[j]<=freq){
                        break;
                    }else{
                        ++count;
                        freq+=k;
                        --j;
                    }

                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            Long k=sc.nextLong();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);

            Long freq=0L;
            int count=0;
           for(int j=array.size()-1;j>=0;j--){
                if(array.get(j)-freq>0){
                    freq+=k;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.*;
import java.util.*;
public class  KillEmAll{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int q=sc.nextInt();
        for(int i=0;i<q;i++){
            int n=sc.nextInt();
            int k=sc.nextInt();
            ArrayList<Integer> array=new ArrayList<>();
            HashSet<Integer>hm=new HashSet<>();
            for(int j=0;j<n;j++){
                int temp=sc.nextInt();
                if(!hm.contains(temp)){
                    hm.add(temp);
                    array.add(temp);
                }
            }
            if(array.size()==1){
                System.out.println(1);
                continue;
            }
            Collections.sort(array);
            int j=array.size()-2;
            int freq=k;
            int count=1;
            while(j>=0){
                if(array.get(j)-freq>0){
                    freq+=k;
                    --j;
                    ++count;
                }else{
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = in.nextInt();

        for(int i=0;i<t;i++) {
            solver.solve(1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n =in.nextInt(),r=in.nextInt();
            ArrayList<Integer> x = new ArrayList<>();

            for(int i=0;i<n;i++){
                x.add(in.nextInt());
            }

            Collections.sort(x);

            int shift = 0,ans = 0;

            for(int i = n-1;i>=0;){
                if(x.get(i)-shift<= 0 ){
                    break;
                }

                ans++;
                shift+=r;
                int j = i;
                while(j >=0 && x.get(j).equals(x.get(i))){
                    j--;
                }
                i=j;
            }

            out.println(ans);
        }
    }

    static class Maths{
        public static long gcd(long a, long b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public Long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = in.nextInt();

        for(int i=0;i<t;i++) {
            solver.solve(1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n =in.nextInt(),r=in.nextInt();
            int[] x = new int[n+1];

            for(int i=0;i<n;i++){
                x[i] = in.nextInt();
            }

            Arrays.sort(x,0,n-1);

            int shift = 0,ans = 0;

            for(int i = n-1;i>=0;){
                if(x[i]-shift<= 0 ){
                    break;
                }

                ans++;
                shift+=r;
                int j = i;
                while(x[j]==x[i]){
                    j--;
                }
                i=j;
            }

            out.println(ans);
        }
    }

    static class Maths{
        public static long gcd(long a, long b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public Long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = in.nextInt();

        for(int i=0;i<t;i++) {
            solver.solve(1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n =in.nextInt(),r=in.nextInt();
            int[] x = new int[n];

            for(int i=0;i<n;i++){
                x[i] = in.nextInt();
            }

            Arrays.sort(x);

            int shift = 0,ans = 0;

            for(int i = n-1;i>=0;){
                if(x[i]-shift<= 0 ){
                    break;
                }

                ans++;
                shift+=r;
                int j = i;
                while(j >=0 && x[j]==x[i]){
                    j--;
                }
                i=j;
            }

            out.println(ans);
        }
    }

    static class Maths{
        public static long gcd(long a, long b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public Long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = in.nextInt();

        for(int i=0;i<t;i++) {
            solver.solve(1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n =in.nextInt(),r=in.nextInt();
            int[] x = new int[n];

            for(int i=0;i<n;i++){
                x[i] = in.nextInt();
            }

            Arrays.sort(x);

            int shift = 0,ans = 0;

            for(int i = n-1;i>=0;){
                if(x[i]-shift<= 0 ){
                    break;
                }

                ans++;
                shift+=r;
                int j = i;
                while(x[j]==x[i]){
                    j--;
                }
                i=j;
            }

            out.println(ans);
        }
    }

    static class Maths{
        public static long gcd(long a, long b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public Long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class CodingLegacy {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Palindrome solver = new Palindrome();
        int t = in.nextInt();

        for(int i=0;i<t;i++) {
            solver.solve(1, in, out);
        }
        out.close();
    }

    static class Palindrome {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int n =in.nextInt(),r=in.nextInt();
            int[] x = new int[n+1];

            for(int i=0;i<n;i++){
                x[i] = in.nextInt();
            }

            Arrays.sort(x,0,n-1);

            int shift = 0,ans = 0;

            for(int i = n-1;i>=0;){
                if(x[i]-shift<= 0 ){
                    break;
                }

                ans++;
                shift+=r;
                int j = i;
                while(j >=0 && x[j]==x[i]){
                    j--;
                }
                i=j;
            }

            out.println(ans);
        }
    }

    static class Maths{
        public static long gcd(long a, long b)
        {
            if (a == 0)
                return b;
            return gcd(b % a, a);
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt(){
            return Integer.parseInt(next());
        }

        public Long nextLong(){
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.math.*;
import java.util.*;
public class KillEmAll {

	public static void main(String[] args) { //TreeSet and HashSet(I suppose all sets)
		//don't permit storage of duplicate values
		Scanner input = new Scanner(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int T = input.nextInt();
		while (T-->0) {
			int N = input.nextInt();
			long r = input.nextLong();
			long ans = 0;
			TreeSet<Long> set = new TreeSet<Long>(Collections.reverseOrder());
			for (int j = 0; j < N; j++) set.add(input.nextLong());
			while (!set.isEmpty()) {
				long cur = set.pollFirst();
				if (cur-ans*r>0) ans++;
				else break;
			}
			System.out.println(ans);
		}
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class KillEmAll {

	public static void main(String[] args) {
		FastScanner input = new FastScanner();
		PrintWriter w = new PrintWriter(System.out);
		int T = input.nextInt();
		for (int i = 1; i <= T; i++) {
			int N = input.nextInt();
			int r = input.nextInt();
			int ans = 0;
			Integer[] a = new Integer[N];
			int seen = 0; //Number of distinct monsters encountered
			for (int j = 0; j < N; j++) a[j]=input.nextInt();
			Arrays.sort(a);
			for (int R = N-1; R>=0; R--) {
				if (R>=1&&a[R]==a[R-1]) continue;
				else {
					seen++;
					int shift = a[R]/r; //Number of shots to kill monster i using shift skill
					if (a[R]%r!=0) shift++;
					int curans = Math.min(shift, seen);
					if (curans<=ans) break;
					ans=Math.max(curans, ans);
				}
			}
			w.println(ans);
			w.flush();
		}
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class KillEmAll {

	public static void main(String[] args) {
		FastScanner input = new FastScanner();
		PrintWriter w = new PrintWriter(System.out);
		int T = input.nextInt();
		for (int i = 1; i <= T; i++) {
			int N = input.nextInt();
			int r = input.nextInt();
			int ans = 0;
			int[] a = new int[N];
			boolean[] v = new boolean[100001];
			int seen = 0; //Number of distinct monsters encountered
			for (int j = 0; j < N; j++) a[j]=input.nextInt();
			Arrays.sort(a);
			for (int R = N-1; R>=0; R--) {
				if (!v[a[R]]) {
					seen++;
					v[a[R]]=true;
					int shift = a[R]/r; //Number of shots to kill monster i using shift skill
					if (a[R]%r!=0) shift++;
					int curans = Math.min(shift, seen);
					if (curans<ans) break;
					ans=Math.max(curans, ans);
				}
			}
			w.println(ans);
			w.flush();
		}
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class KillEmAll {

	public static void main(String[] args) {
		FastScanner input = new FastScanner();
		PrintWriter w = new PrintWriter(System.out);
		int T = input.nextInt();
		for (int i = 1; i <= T; i++) {
			int N = input.nextInt();
			long r = input.nextLong();
			long ans = 0;
			long[] a = new long[N];
			int seen = 0; //Number of distinct monsters encountered
			for (int j = 0; j < N; j++) a[j]=input.nextLong();
			Arrays.sort(a);
			for (int R = N-1; R>=0; R--) {
				if (R>=1&&a[R]==a[R-1]) continue;
				else {
					if (a[R]<=ans*r) break; //Basically, if current monster is already <= 0
					seen++;
					long shift = a[R]/r; //Number of shots to kill monster i using shift skill
					if (a[R]%r!=0) shift++;
					long curans = Math.min(shift, seen);
					ans=Math.max(curans, ans);
				}
			}
			w.println(ans);
			w.flush();
		}
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}