#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    int sum=0,i;
    int S=L/v;
    for( i=v ; i<=L ; i+=v)
    {
        if(i>=l)
        break;
    }
    if(i>r)
    {
         printf("%d\n",S);
         continue;
    }
    else if(i==r)
    {
        printf("%d\n",S-1);
    }
    else
    {
        sum=(r-i)/v+1;
        printf("%d\n",S-sum);
    }

    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    if(l==1&&r==L)
    {
        puts("0");
        return 0;
    }
    int S=L/v;
    int sum=0;
    for(int i=l ; i<=r ;)
    {
        if(i%v!=0)
        i++;
        else
        {
            i+=v;
            sum++;
        }

    }
    printf("%d\n",S-sum);
    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    if(l==1&&r==L)
    {
        puts("0");
        continue;
    }
    int S=L/v;
    int sum=0,i;
    for( i=l ; i<=r ;i++)
    {

      if(i%v==0)
      break;
    }
      sum=(r-i)/v;
     printf("%d\n",S-sum-1);
    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    int sum=0;
    for(int i=v ; i<=L ; i+=v)
    {
        if(i<l||i>r)
        sum++;
    }
    printf("%d\n",sum);
    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    if(l==1&&r==L)
    {
        puts("0");
        return 0;
    }
    int S=L/v;
    int sum=0,i;
    for( i=l ; i<=r ;i++)
    {

      if(i%v==0)
      break;
    }
      sum=(r-i)/v;
     printf("%d\n",S-sum-1);
    }
}


#include<bits/stdc++.h>

using namespace std ;

int main( )
{
    int T;
    scanf("%d",&T);
    while(T--)
    {

    int L,v,l,r;
    scanf("%d%d%d%d",&L,&v,&l,&r);
    int sum=0,i;
    int S=L/v;
    for( i=v ; i<=L ; i+=v)
    {
        if(i>=l)
        break;
    }
    if(i>=r)
    {
         printf("%d\n",S-1);
         continue;
    }
    else
    {
        sum=(r-i)/v;
        printf("%d\n",S-sum-1);
    }

    }
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main(){

  int t;
  cin>>t;

  ll L,v,l,r;

  while(t--){
    cin>>L>>v>>l>>r;
    ll x = (r-l)/v;
    if(l%v==0 || r%v==0) x++;
    cout<<L/v - x;
    cout<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main(){

  int t;
  cin>>t;

  ll L,v,l,r;

  while(t--){
    cin>>L>>v>>l>>r;
    ll x = (l-r)/v;
    if(l%v==0 || r%v==0) x++;
    cout<<L/v - x;
    cout<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main(){

  int t;
  cin>>t;

  ll L,v,l,r;

  while(t--){
    cin>>L>>v>>l>>r;
    cout<<L/v + (l-r-1)/v;
    cout<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main(){

  int t;
  cin>>t;

  ll L,v,l,r;

  while(t--){
    cin>>L>>v>>l>>r;
    cout<<L/v - r/v + (l-1)/v;
    cout<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main(){

  int t;
  cin>>t;

  while(t--){
    ll L,v,l,r;
    vector<ll> vi;
    cin>>L>>v>>l>>r;

    while(l%v!=0){
      l++;
    }
  while(r%v!=0){
    r--;
  }

    cout<<((L/v) - ((r-l)/v))-1;
    cout<<endl;

  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main(){

  int t;
  cin>>t;

  while(t--){
    ll L,v,l,r;
    cin>>L>>v>>l>>r;

    // cout<<(L/v) - ((r-l)/v);
    // cout<<(L/v) - ()
    // cout<<endl;
  //   while(l%v!=0){
  //     l++;
  //   }
  // while(r%v!=0){
  //   r--;
  // }

    // cout<<((L/v) - ((r-l)/v))-1;

//  ll x = ceil  (r, v);
//  ll y = floor (l, v);

// ll xx =(floor)(r/v) - (floor)(l/v) - (r%v==0);

    ll xx = (r-l)/v;
    if(l%v==0 || r%v==0) xx++;

  cout<<(L/v) - xx;
  cout<<endl;

  }

  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main(){

  int t;
  cin>>t;

  while(t--){
    ll L,v,l,r;
    cin>>L>>v>>l>>r;

    if(L==r && v==l){
        cout<<0<<endl;
        continue;
    }

    ll xx = (r-l)/v;
    if(l%v==0 || r%v==0) xx++;

  cout<<(L/v) - xx;
  cout<<endl;

  }

  return 0;
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        int ans=L/v;

        while(l%v!=0){
            l++;
        }

        cout << ans-(r-l+1) << endl;

    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

       // cout << floor((float)r/v) << " " << ceil((float)l/v) << endl;

        cout << L/v-(floor((float)r/v)-ceil((float)l/v)+1) << endl;

    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        int ans=L/v;

        while(l%v!=0){
            l++;
        }

        cout << ans-(r-l+1)/v << endl;

    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        int ans=L/v;

        while(l%v!=0 && l<r){
            l++;
        }

        if(l-1<r)
            ans--;

        cout << ans-(r-l)/v << endl;

    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        cout << L/v-(r/v-(l-1)/v) << endl;
    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        int ans=L/v;

        for(int i=l;i<=r;i++){
            if(i%v==0)
                ans--;
        }

        cout << ans << endl;

    }
}


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

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

    while(t--){
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        int ans=0;

        if(l%v==0)
            ans++;

        int an=L/v-(r-l)/v;
        cout << an-ans << endl;
    }
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = ((end - start) / v);
    if (start % v == 0 || end % v == 0)
      a++;

    if (v > start && v < end)
      a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = ((end - start) / v);
    if (start % v == 0 || end % v == 0)
      a++;

    if (!a && (v > start && v < end))
      a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = end / v;
    a -= start / v;

    if (start % v == 0 || end % v == 0)
      a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = 0;
    if (start % v == 0)
      a = 1;

    printf ("%d\n", (l / v) - ((end - start) / v) - a);
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    if (start % v)
      start += v - (start % v);

    if (end % v)
      end -= (end % v);

    int a;
    a = (end - start) / v;
    a++;

    //printf ("start: %d, end: %d, a: %d\n", start, end, a);

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = 0;
    if (start % v == 0 || (v >= start && v <= end))
      a = 1;

    printf ("%d\n", (l / v) - ((end - start) / v) - a);
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = 0;
    if (start % v == 0 || end % v == 0)
      a++;

    if (!a && (v > start && v < end))
      a++;

    a += ((end - start) / v);

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    while (start % v)
      start++;

    while (end % v)
      end--;

    int a;
    a = (end - start) / v;
    a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = ((end - start) / v);
    if (start % v == 0 || end % v == 0)
      a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    int a = 0;
    if (start % v == 0 || (((end - start) / v) < 1 && (v >= start && v <= end)))
      a = 1;

    printf ("%d\n", (l / v) - ((end - start) / v) - a);
  }
  return 0;
}


#include <bits/stdc++.h>

int main () {
  int t; scanf ("%d", &t);

  for (int c = 0; c < t; c++) {
    int l, v, start, end;
    scanf ("%d%d%d%d", &l, &v, &start, &end);

    start += start % v;

    end -= end % v;

    int a;
    a = (end - start) / v;
    a++;

    printf ("%d\n", (l / v) - (a));
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    cout<<((Lg/freq)-((Lg/(left1))-(Lg/(right1+1))))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    cout<<((Lg/freq)-((Lg/(left1))-(Lg/(right1))))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Le,freq,left1,right1;
    cin>>Le>>freq>>right1;
    cout<<((Le/freq)-((Le/(left1))-(Le/(right1))))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>right1;
    cout<<((Lg/freq)-((Lg/(left1))-(Lg/(right1))))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    ll k=left1/freq;
    k*=freq;
    if(left1%freq){
    k+=freq;
    }
    ll g=right1/freq;
    g*=freq;
    if(g<k){
    cout<<(Lg/freq)<<endl;}
    else {
    cout<<((Lg/freq)-((g-k+freq)/freq))<<endl;
    }
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    int Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    ll k=left1/freq;
    k*=freq;
    if(left1%freq){
    k+=freq;
    }
    ll g=right1/freq;
    g*=freq;
    if(g<k){
    cout<<(Lg/freq)<<endl;}
    else {
    cout<<((Lg/freq)-((g-k+freq)/freq))<<endl;
    }
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    ll k=left1/freq;
    k*=freq;
    ll g=right1/freq;
    g*=freq;
    cout<<((Lg/freq)-((g-k)/freq))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    ll k=left1/freq;
    k*=freq;
    ll g=right1/freq;
    g*=freq;
    cout<<((Lg/freq)-((g-k+1)/freq))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    int Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    int k=left1/freq;
    k*=freq;
    if(left1%freq){
    k+=freq;
    }
    int g=right1/freq;
    g*=freq;
    if(g<k){
    cout<<(Lg/freq)<<endl;}
    else {
    cout<<((Lg/freq)-((g-k+freq)/freq))<<endl;
    }
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Le,freq,left1,right1;
    cin>>Le>>freq>>right1;
    cout<<((Le/freq)-((Le/(left1-1))-(Le/(right1))))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
  {
    ll Lg,freq,left1,right1;
    cin>>Lg>>freq>>left1>>right1;
    ll k=left1/freq;
    k*=freq;
    ll g=right1/freq;
    g*=freq;
    if(g==k){
    g+=freq;
    }
    cout<<((Lg/freq)-((g-k)/freq))<<endl;
  }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll x=a/v;
        ll res=x - (r-l)/v;
        if(r%v==0 || l%v==0) res-=1;
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v + (l-1)/v - r/v;
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll x=a/v;
        ll res=x-(r-l)/v;
        if(r%v==0 || l%v==0) res--;
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v;
        if(r-l<v){
            ll y=l%v;
            y=v-y;
            if(l+y<=r) res--;
            if(r%v==0 || l%v==0) res--;
        }
        else{
            ll b=(r-l)/v;
            res=res-b;
            if(r%v==0 || l%v==0) res-=1;
        }
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll x=a/v;
        ll res=x - abs(r-l)/v;
        if(abs(r-l)/v==0){
            if((r%v + abs(r-l))/v==1 || ((l%v + abs(r-l))/v==1)) res++;
        }
        if(r%v==0 || l%v==0) res-=1;
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v;
        if(r-l<v){
            ll y=l%v;
            ll z=v-y;
            if(z+l<=r) res++;
            if(r%v==0 || l%v==0) res-=1;
        }
        else{
            ll b=(r-l)/v;
            res=res-b;
            if(r%v==0 || l%v==0) res-=1;
        }
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v;
        if(r-l<v){
            ll y=l%v;
            ll z=v-y;
            if(z+l<=r) res--;
            if(r%v==0 || l%v==0) res-=1;
        }
        else{
            ll b=(r-l)/v;
            res=res-b;
            if(r%v==0 || l%v==0) res-=1;
        }
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v;
        if(l-r<v){
            for(ll i=l; i<=r; i++){
            if(i%v==0) res--;
            }
        }
        else{
            res-=(r-l)/v;
        }
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
int const M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e9+10;
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
ll pow(ll a, ll b){ll res = 1;for(int i = 1; i<=b; ++i) res *= a;return res;}
ll isPrime(ll n){for(ll i=2; i<=sqrt(n); i++){if(n%i==0) return 0;}return 1;}
bool isPrime_opt(ll n){if (n <= 1)  return false;if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false;for(ll i=5; i*i<=n; i=i+6)if(n%i == 0 || n%(i+2) == 0) return false;return true;}
ll fact(ll n){if(n==0 || n==1) return 1; else return n*fact(n-1);}
ll gcd (ll a, ll b) {return b ? gcd (b, a % b) : a;}
ll lcm(ll a, ll b){return (a/gcd(a,b))*b;}
int a[18]={2,3,5,7,11,13,13,17,19,23,29,31,37,41,43,47,53,59};
ll binarySearch(ll low,ll high,ll key){while(low<=high){ll mid=(low+high)/2;if(a[mid]<key){low=mid+1;}else if(a[mid]>key){high=mid-1;}else{return mid;}}return -1;}
void Sieve(ll n, ll prime[]){for(int p=2; p*p<=n; p++){if(prime[p] == true){for(int i=p*2; i<=n; i += p)prime[i] = false;}}for(int p=2; p<=n; p++)if(prime[p])cout << p << " ";}
ll factor(ll n){ll cnt=0;for(ll i=1; i<=n; i++){if(n%i==0){cnt++;}}return cnt;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	for(ll i=0; i<t; i++){
        ll a,v,l,r;
        cin >> a >> v >> l >> r;
        ll res=a/v;
        if(r-l<v){
            ll y=l%v;
            ll z=v-y;
            if(z+l<=r) res++;
        }
        else{
            ll b=(r-l)/v;
            res=res-b;
        }
        if(r%v==0 || l%v==0) res-=1;
        cout << res << "\n";
	}
	return 0;
}
/* The judge is never wrong! Your code is buggy 😈
   Look for:
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int dem=0;
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        if(k%v==0)dem=1;
        cout<<(l-1)/v+(k-r)/v<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+(v-l%v);
        if(r%v!=0)r=r-r%v;
        if(k%v!=0)k=k-k%v;
        cout<<(l-v)/v+(k-r)/v<<endl;
        cout<<k<<" "<<v<<" "<<l<<" "<<r;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        if(l/v-1+(k-r)/v>0)cout<<l/v-1+(k-r)/v<<endl;
        else cout<<0<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        if(l%v!=0)l=l+(v-l%v);
        if(r%v!=0)r=r-r%v;
        if(k%v!=0)k=k-k%v;
        cout<<(l-v)/v+(k-r)/v<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        int dem=0;
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        if(k%v==0)dem=1;
        cout<<(l-v)/v+(k-r)/v<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        if(l/v-1+(k-r)/v>0)cout<<l/v-1+(k-r)/v<<endl;
        else cout<<0;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+(v-l%v);
        if(r%v!=0)r=r-r%v;
        if(k%v!=0)k=k-k%v;
        cout<<(l-v)/v+(k-r)/v<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        if(k%v!=0)k=k-(v-k%v);
        cout<<(l-v)/v+(k-r)/v<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        long long k,v,l,r;
        cin>>k>>v>>l>>r;
        l=l+l%v;
        if(r%v!=0)r=r-(v-r%v);
        cout<<l/v-1+(k-r)/v<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    int L,v,l,r,c=1;
    cin>>L>>v>>l>>r;
    vector<int>lanterns;
    while(c*v<=L){
       if(c*v<l || c*v>r) lanterns.push_back(c*v);
        c+=1;
    }
    cout<<lanterns.size()<<"\n";
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    long long L,v,l,r,counter=0,c=1,divisors=0;
    cin>>L>>v>>l>>r;
 if(v>r){
        while(c*v<=L){counter+=1;c+=1;}
        cout<<counter<<"\n";
        continue;
    }
    else{
        while(c*v<l){
            counter+=1;
            c+=1;
        }
         int start=r/v;
         c=start+1;
         while(c*v<=L){
            counter+=1;
            c+=1;
         }

 cout<<counter<<"\n";
}}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int L,v,l,r,num=0,counter=0,start=0,last=0;
cin>>L>>v>>l>>r;
for(int i=l;i<=r;++i){
    if(i>=v && i%v==0){start=i;break;}
}
for(int i=r;i>=l;--i){
    if(i>=v && i%v==0){last=i;break;}
}
if(start>0 && last>0){
    num=((last-start)/v)+1;
}
else if(start==0 && last>0 || last==0 && start>0){num=1;}
start=0;last=0;

for(int i=v;i<=L;++i){
    if(i%v==0){start=i;break;}
}
for(int i=L;i>=1;--i){
    if(i>=v && i%v==0){last=i;break;}
}
if(start>0 && last>0){counter=((last-start)/v)+1;}
else if(start>0 && last==0 || start==0 && last>0){counter=1;}
cout<<counter-num<<"\n";
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
    int L,v,l,r,counter=0,c=1;
    cin>>L>>v>>l>>r;
 if(v>r){
        while(c*v<=L){counter+=1;c+=1;}
        cout<<counter<<"\n";
        continue;
    }
    else{
        while(c*v<l){
            counter+=1;
            c+=1;
        }
         int start=r/v;
         c=start+1;
         while(c*v<=L){
            counter+=1;
            c+=1;
         }

 cout<<counter<<"\n";
}}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int L,v,l,r,num=0,counter=0,start=0,last=0,c=1;
cin>>L>>v>>l>>r;
if(l>=v){c=l/v;if(l%v!=0)c+=1;if(c*v<=r)start=c*v;}
else if(c*v<=r){start=c*v;}
if(r>=v){c=r/v;if(c*v>=l)last=c*v;}
if(start>0 && last>0){
    num=((last-start)/v)+1;
}
else if(start==0 && last>0 || last==0 && start>0){num=1;}
start=0;last=0;
if(v<=L){c=1;start=c*v;}
if(v<=L){c=L/v;last=c*v;}
if(start>0 && last>0){counter=((last-start)/v)+1;}
else if(start>0 && last==0 || start==0 && last>0){counter=1;}
cout<<counter-num<<"\n";

}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    long long L,v,l,r,c=1;
    cin>>L>>v>>l>>r;
    vector<long long>lanterns;
    while(c*v<=L){
       if(c*v<l || c*v>r) lanterns.push_back(c*v);
        c+=1;
    }
    cout<<lanterns.size()<<"\n";
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
    int L,v,l,r,counter=0,c=1;
    cin>>L>>v>>l>>r;
 if(v>r){
        while(c*v<=L){counter+=1;c+=1;}
        cout<<counter<<"\n";
        continue;
    }
    else{
            if(v==1){c=l-1;if(l-1>=0)counter=c;}
        else{while(c*v<l){
            counter+=1;
            c+=1;
        }}
         int start=r/v;
         c=start+1;
         if(v==1){c=r;if(L-r>=0)counter+=(L-r);}
         else{while(c*v<=L){
            counter+=1;
            c+=1;
         }}

 cout<<counter<<"\n";
}}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    long long L,v,l,r,counter=0,c=1;
    cin>>L>>v>>l>>r;
    if(v==1){c=l-1;if(c>=0)counter=c;}
    else {while(c*v<l){
        counter+=1;
        c+=1;
    }}
    if(v==1){c=r+1;if(L-c>=0)counter+=c;}
    while(c*v<=r)c+=1;
    while(c*v<=L){
        counter+=1;
        c+=1;
    }

 cout<<counter<<"\n";
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    long long L,v,l,r,counter=0;
    cin>>L>>v>>l>>r;
    for(int i=1;i<l;++i){
        if(i>=v && i%v==0)counter+=1;
    }
    for(int i=r+1;i<=L;++i){
        if(i>=v && i%v==0)counter+=1;
    }
 cout<<counter<<"\n";
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--){
int L,v,l,r,num=0,counter=0,start=0,last=0,c=1;
cin>>L>>v>>l>>r;
if(l>=v){c=l/v;if(l%v!=0)c+=1;if(c*v<=r)start=c*v;}
if(r>=v){c=r/v;if(c*v>=l)last=c*v;}
if(start>0 && last>0){
    num=((last-start)/v)+1;
}
else if(start==0 && last>0 || last==0 && start>0){num=1;}
start=0;last=0;
if(v<=L){c=1;start=c*v;}
if(v<=L){c=L/v;last=c*v;}
if(start>0 && last>0){counter=((last-start)/v)+1;}
else if(start>0 && last==0 || start==0 && last>0){counter=1;}
cout<<counter-num<<"\n";

}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    long long L,v,l,r,counter=0,c=1;
    cin>>L>>v>>l>>r;
    if(v==1){c=l-1;if(c>=0)counter=c;}
    else {while(c*v<l){
        counter+=1;
        c+=1;
    }}
    if(v==1){c=r+1;if(L-c>=0)counter+=(L-r);}
    else{while(c*v<=r)c+=1;
    while(c*v<=L){
        counter+=1;
        c+=1;
    }}

 cout<<counter<<"\n";
}
return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		ans-=(r-l+1)/v+(r%v==0 || l%v==0);
		if(v==1)
			ans++;
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		ans-=r/v-(l-1)/v;
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		ans-=(r-l+1)/v+(r%v==0 && l%v==0);
		if(v==1)
			ans++;
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		ans-=(r-l+1)/v;
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		if(v<l)
			l+=l%v;
		if(v<r)
			r-=r%v;

		ans-=(r-l)/v;
		ans--;
		cout << ans << endl;
	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		int flag=1;
		if(v>r)
		{
			cout << ans << endl;
			continue;
		}
		else
			r-=r%v;

		if(l>v)
			l+=l%v;
		else
			l=v;

		if(l<=r)
			ans-=(r-l)/v+1;
		cout << ans << endl;

	}

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(0);
	int t,L,v,l,r;
	cin >> t;
	while(t--)
	{
		cin >> L >> v >> l >> r;
		int ans=L/v;
		ans-=(r-l)/v+(r%v==0 || l%v==0);
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
using  namespace std;

int main() {

    int T;
    cin >> T;
    while(T--){

        long long  int L , v , l , r ,  no_of_platforms , key , next , previous;
        int i, j , count = 0 , train_length , flag;
        cin >> L >> v >> l >> r;

        no_of_platforms = L / v;
        train_length = r - l +1;
        if(train_length == L || v == L)
            key = 0;

        else {
            i = l;
            j = r;
            while(true) {
                if (i % v == 0) {
                    next = i;
                    break;
                } else {
                    i++;
                    continue;
                }
            }

            while(true){
                if(j % v == 0) {
                    previous = j;
                    break;
                } else{
                    j--;
                    continue;
                }
            }
            count = (previous - next) / v;
            count ++;
            key = no_of_platforms - count;
        }

        cout << key << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {

        int count, final, diff , total_count , temp;
        int L , v , l , r;
        cin >> L >> v >> l >> r;

        total_count = L / v;
        diff = r - l;

        count = diff / v;

        final = total_count - count;
        if(l % v == 0 || r % v ==0)
            final--;

        if(diff < v){
            temp = l / v;
            temp++;
            temp *= v;
            if(temp > l && temp < r)
                final--;
        }

        cout << final << endl;

    }
}


#include <iostream>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {

        int count, final, diff , total_count;
        int L , v , l , r;
        cin >> L >> v >> l >> r;

        total_count = L / v;
        diff = r - l;

        count = diff / v;

        final = total_count - count;
        if(l % v == 0 || r % v ==0)
            final--;

        cout << final << endl;

    }
}


#include <iostream>
using  namespace std;

int main() {

    int T;
    cin >> T;
    while(T--){

        int L , v , l , r ,  no_of_platforms , key , next , previous;
        int i, j , count = 0 , train_length , flag;
        cin >> L >> v >> l >> r;

        no_of_platforms = L / v;
        train_length = r - l +1;
        if(train_length == L || v == L)
            key = 0;

        else {
            i = l;
            j = r;
            while(true) {
                if (i % v == 0) {
                    next = i;
                    break;
                } else {
                    i++;
                    continue;
                }
            }

            while(true){
                if(j % v == 0) {
                    previous = j;
                    break;
                } else{
                    j--;
                    continue;
                }
            }
            count = (previous - next) / v;
            count ++;
            key = no_of_platforms - count;
        }

        cout << key << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {

        int count, final, diff , flag = 0 , total_count , temp , half_distance , temp2;
        int L , v , l , r;
        cin >> L >> v >> l >> r;

        total_count = L / v;

        half_distance = v / 2;
        diff = r - l ;

        temp = l / v;
        temp++;
        temp *= v;

        temp2 = r / v;
        temp2 *= v;

        count = diff / v;

        cout << count<< " <--" << endl;

        if(l > temp - half_distance && r < temp2 + half_distance){
            count++;
            flag = -1;
        }

        cout << "total_count :" << total_count << endl;
        cout << "count :" << count << endl;

        final = total_count - count;

        if(l % v == 0 || r % v ==0)
            final--;

        if(diff < v && flag != -1){
            if(temp > l && temp2 < r)
                final--;
        }

        cout << final << endl;
    }
}


#include <iostream>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {

        int final , total_count , temp1 , temp2;
        int L , v , l , r;
        cin >> L >> v >> l >> r;

        total_count = L / v;
        temp1 = l / v;
        temp2 = r / v;

        if( l % v == 0)
        {
            final = total_count - ( temp2 - temp1 );
            final--;
        }
        else
        {
            final = total_count -( temp2 - temp1);
        }

        cout << final << endl;
    }
}


#include <iostream>
using  namespace std;

int main() {

    int T;
    cin >> T;
    while(T--){

        long long  int L , v , l , r;
        long long int i , count = 0 , key , no_of_platforms , train_length;
        cin >> L >> v >> l >> r;

        no_of_platforms = L / v;
        train_length = r - l +1;
        if(train_length == L)
            key = 0;

        else {

            for (i = l; i <= r; i++) {

                if (i % v == 0)
                    count++;
            }
            key = no_of_platforms - count;
        }

        cout << key << endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int T;
    cin >> T;
    while (T--) {

        int count, final, diff , flag = 0 , total_count , temp , half_distance , temp2;
        int L , v , l , r;
        cin >> L >> v >> l >> r;

        total_count = L / v;

        half_distance = v / 2;
        diff = r - l ;

        temp = l / v;
        temp++;
        temp *= v;

        temp2 = r / v;
        temp2 *= v;

        count = diff / v;

        if(l > temp - half_distance && r < temp2 + half_distance){
            count++;
            flag = -1;
        }

        final = total_count - count;

        if(l % v == 0 || r % v ==0)
            final--;

        if(diff < v && flag != -1){
            if(temp > l && temp2 < r)
                final--;
        }

        cout << final << endl;
    }
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    unsigned int t, L, r, l, v, a, b;
    cin >> t;
    for(unsigned int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        if(l == 1 && r == L)
        {
            cout << 0;
            continue;
        }
        a = (l-1)/v;
        b = (L-r)/v;
        if((r+1)%v == 0 && v!=1)
        {
            b++;
        }
        cout << a + b << "\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b, c;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        b = (r - l)/v;
        if(v > (r-l))
        {
            c = r/v;
            c*= v;
            if(l <= c && r >= c)
            {
                b++;
            }
        }
        else if(r%v == 0 || l%v == 0)
        {
            b++;
        }
        cout << a-b << " ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        b = (r - l)/v;
        if(r%v == 0 || l%v == 0)
        {
            b++;
        }
        cout << a-b << " ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b, c, d;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        if(l%v == 0)
        {
            c = l/v;
        }
        else
        {
            c = (l+v)/v;
        }
        d = (r+v)/v;
        b = d - c;
        cout << a-b << "\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b, c, d;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        if(v > (r-l))
        {
            c = r/v;
            c*= v;
            if(l <= c && r >= c)
            {
                b = 1;
            }
            else
            {
                b = 0;
            }
        }
        else if(v == 1)
        {
            cout << L - r + l - 1 << "\n";
            continue;
        }
        else
        {
            if(l%v == 0)
            {
                c = l/v;
            }
            else
            {
                c = (l+v)/v;
            }
            if(r%v == 0)
            {
                d = r/v;
            }
            else
            {
                d = (r+v)/v;
            }
            b = d - c;
        }
        cout << a-b << "\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b, c, d;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        if(v > (r-l))
        {
            c = r/v;
            c*= v;
            if(l <= c && r >= c)
            {
                b = 1;
            }
            else
            {
                b = 0;
            }
        }
        else if(v == 1)
        {
            cout << L - r + l - 1 << "\n";
            continue;
        }
        else
        {
            if(l%v == 0)
            {
                c = l/v;
            }
            else
            {
                c = (l+v)/v;
            }
            d = (r+v)/v;
            b = d - c;
        }
        cout << a-b << "\n";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t, L, r, l, v, a, b, c;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> L >> v >> l >> r;
        a = L/v;
        b = (r - l)/v;
        if(v > (r-l))
        {
            c = r/v;
            c*= v;
            if(l <= c && r >= c)
            {
                b++;
            }
        }
        else if(r%v == 0 || l%v == 0)
        {
            b++;
        }
        cout << a-b << "\n";
    }
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

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

    while(t--)
    {
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        if(l == 1 && r == L) {cout << "0" << endl ; continue;}

        cout << (l-1)/v + (L)/v - r/v << endl;
    }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

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

    while(t--)
    {
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        if(l == 1 && r == L) {cout << "0"; continue;}

        int count = 0;

        for(int i=v ; i<l ; i++)
        {
            if(i%v == 0)
            {
                count++;
                i += v;
            }
        }

        for(int i=r+1 ; i<=L ; i++)
        {
            if(i%v == 0)
            {
                count++;
                i += v;
            }
        }
        cout << count << endl;
    }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;

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

    while(t--)
    {
        int L,v,l,r;
        cin >> L >> v >> l >> r;

        if(l == 1 && r == L) {cout << "0"; continue;}

        int count = 0;

        for(int i=v ; i<l ; )
        {
            if(i%v == 0)
            {
                count++;
                i += v;
            }
            else i++;
        }

        for(int i=r+1 ; i<=L ; )
        {
            if(i%v == 0)
            {
                count++;
                i += v;
            }
            else i++;
        }
        cout << count << endl;
    }

    return 0;
}


//... copyright @ASHISH JHA ... _/\_******
/*Licensed under the "THE BEER-WARE LICENSE" (Revision 42):
  Ashish_Jha wrote this file. As long as you retain this notice you
  can do whatever you want with this stuff. If we meet some day, and you think
  this stuff is worth it, you can buy me a beer or coffee in return
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define chal(n) for(ll i=0;i<n;i++)
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)9
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mp make_pair
bool IsPowerOfTwo(ll x){ return (x != 0) && ((x & (x - 1)) == 0);}
ll poer(ll a,ll b){ll rs=1; while(b>0) { if(b&1) rs*=a; a*=a; b/=2;} return rs;}
ll mod_poer(ll a,ll b,ll mo){ll rs=1; while(b>0) { if(b&1) rs=(rs*a)%mo; a=(a*a)%mo; b/=2;} return rs%mo;}
ll d,x,y;
void ext_euclid(ll a,ll b){ if(b==0){d=a;x=1;y=0;}else{ext_euclid(b,a%b);ll temp=x;x=y;y=temp-(a/b)*y;}}
ll mod_inverse1(ll a,ll m){ext_euclid(a,m);return (x%m+m)%m;}
ll mod_inverse2(ll a,ll m){return mod_poer(a,m-2,m);}
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}

// never take ll as return type of find operation in strings
// never take d,x,y as variables
ll n,k,sum=0,glo;
vector<ll> adj[200005];
ll vis[100005];
void dfs(ll st,ll dis)
{
    vis[st]=1;
    chal(adj[st].size())
    {
        if(!vis[adj[st][i]])
        {
           ll re=dis+1;
           if(adj[st][i]>glo)
           {
               if(re%k!=0)
                sum+=(re/k+1);
               else
                sum+=re/k;
            }
            dfs(adj[st][i],re);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

   cin>>n>>k;
chal(n-1)
{
    ll u,v;
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
}
for(ll i=1;i<=n;++i)
{
    memset(vis,0,sizeof(vis));
    glo=i;
    dfs(i,0);
}
cout<<sum<<endl;
return 0;
}


//... copyright @ASHISH JHA ... _/\_******
/*Licensed under the "THE BEER-WARE LICENSE" (Revision 42):
  Ashish_Jha wrote this file. As long as you retain this notice you
  can do whatever you want with this stuff. If we meet some day, and you think
  this stuff is worth it, you can buy me a beer or coffee in return
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define chal(n) for(ll i=0;i<n;i++)
#define si1(a) scanf("%d",&a)
#define si2(a,b) scanf("%d%d",&a,&b)
#define si3(a,b,c) scanf("%d%d%d",&a,&b,&c)9
#define sl1(a) scanf("%lld",&a)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mp make_pair
bool IsPowerOfTwo(ll x){ return (x != 0) && ((x & (x - 1)) == 0);}
ll poer(ll a,ll b){ll rs=1; while(b>0) { if(b&1) rs*=a; a*=a; b/=2;} return rs;}
ll mod_poer(ll a,ll b,ll mo){ll rs=1; while(b>0) { if(b&1) rs=(rs*a)%mo; a=(a*a)%mo; b/=2;} return rs%mo;}
ll d,x,y;
void ext_euclid(ll a,ll b){ if(b==0){d=a;x=1;y=0;}else{ext_euclid(b,a%b);ll temp=x;x=y;y=temp-(a/b)*y;}}
ll mod_inverse1(ll a,ll m){ext_euclid(a,m);return (x%m+m)%m;}
ll mod_inverse2(ll a,ll m){return mod_poer(a,m-2,m);}
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}

// never take ll as return type of find operation in strings
// never take d,x,y as variables
vector<ll> adj[200005];
ll sum[200005][6],n,k,ans=0,cnt[200005][6];
ll vis[200005];
void dfs(ll st)
{
    cnt[st][0]++;
   chal(adj[st].size())
    {
        ll re=adj[st][i];
        if(!vis[re])
        {
            ll c[6],s[6];
            for(ll j=0;j<6;j++)
            {
                c[j]=0;
                s[j]=0;
            }
            vis[re]=1;
            dfs(re);
            for(ll j=0;j<k;j++)
            {
                c[j]=cnt[re][(j+k-1)%k];
            }
            for(ll j=0;j<k;j++)
            {
                s[j]=sum[re][(j+k-1)%k];
            }
            s[0]+=c[0];
            for(ll p=0;p<k;p++)
            {
                for(ll q=0;q<k;q++)
                {
                    ll val=(p+q)/k;
                    if((p+q)%k!=0)
                        val++;
                    ans+=(sum[st][p]*c[q]+s[q]*cnt[st][p]+val*cnt[st][p]*c[q]);
                }
            }
            for(ll p=0;p<k;p++)
            {
                sum[st][p]+=s[p];
                cnt[st][p]+=c[p];
            }
        }
    }

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n>>k;
    chal(n-1)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    memset(vis,0,sizeof(vis));
    vis[1]=1;
    dfs(1);
    cout<<ans<<endl;
    return 0;
}


#include<string>
#include<vector>
#include<regex>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
#include<sstream>
#include<stack>
#include<iostream>
#include<limits>
#include<bitset>
#include<list>
#include<queue>
#include<array>
#include<memory>
#include<functional>
#include<unordered_map>
#include<complex>
using namespace std;
namespace tree_split2
{
	const int N = 410000;
	int k;
	struct graph
	{
		int Begin[N * 2], to[N * 2], Next[N * 2], e, weight[N * 2];
		void add(int u, int v)
		{
			to[++e] = v;
			Next[e] = Begin[u];
			Begin[u] = e;
		}
		void add(int u, int v, int w)
		{
			to[++e] = v;
			Next[e] = Begin[u];
			Begin[u] = e;
			weight[e] = w;
		}
		void init_graph()
		{
			e = 0;
			memset(Begin, -1, sizeof(Begin));
		}
	};
	graph p;
	bool vis[N];
	int root, size1[N], size2[N], allnode;
	void getroot(int now, int fa)  //得到根
	{
		size1[now] = 1;
		size2[now] = 0;
		for (int i = p.Begin[now]; i != -1; i = p.Next[i])
		{
			int t = p.to[i];
			if (t == fa || vis[t]) continue;
			getroot(t, now);
			size1[now] += size1[t];
			size2[now] = max(size2[now], size1[t]);
		}
		size2[now] = max(allnode - size1[now], size2[now]);
		if (size2[now] < size2[root]) root = now;
	}
	long long ans;
	int deep[2 * N];
	unordered_map<int, int> sum;
	long long sum_0,sz;
	void getdeep(int r, int fa) //当前轮处理数据
	{
		if (r != root)
		{
			sum_0 += deep[r] / k;
			sum[deep[r] % k]++;
			sz++;
		}
		for (int i = p.Begin[r]; i != -1; i = p.Next[i])
		{
			if (p.to[i] != fa && vis[p.to[i]] == false)
			{
				deep[p.to[i]] = deep[r] + p.weight[i];
				getdeep(p.to[i], r);
			}
		}
	}

	void calc2(int a, int fa)//计算当前子树
	{
		ans += (deep[a] / k)*(sz+1);
		int kkk = deep[a] % k;
		if (kkk != 0)
			ans++;
		ans += sum_0;
		for (int i = 0; i < 5; ++i)
			if (kkk + i > 0 && kkk + i <= k)
				ans += sum[i];
			else if (kkk + i > k)
				ans += sum[i] * 2;
		//cout << a << " " << root << " " << ans << " " << sum_0 <<" "<<deep[a]/k<<" "<<sz<< endl;
		for (int i = p.Begin[a]; i != -1; i = p.Next[i])
		{
			if (p.to[i] != fa && vis[p.to[i]] == false)
				calc2(p.to[i], a);
		}
	}
	int sumnode;
	void del_(int a, int fa, int now) //清除当前子树贡献
	{
		sumnode++;
		sum_0 -= deep[a] / k;
		sum[deep[a] % k]--;
		sz--;
		for (int i = p.Begin[a]; i != -1; i = p.Next[i])
		{
			if (p.to[i] != fa && vis[p.to[i]] == false)
				del_(p.to[i], a, now);
		}
	}
	void ins_(int a, int fa)//回退当前子树贡献
	{
		sum_0 += deep[a] / k;
		sum[deep[a] % k]++;
		sz++;
		for (int i = p.Begin[a]; i != -1; i = p.Next[i])
		{
			if (p.to[i] != fa && vis[p.to[i]] == false)
				ins_(p.to[i], a);
		}
	}
	int all_[N * 2];
	void calc(int r)
	{
		getroot(r, r);
		vis[root] = true;
		deep[root] = 0;
		sum_0 = 0;
		sz = 0;
		sum.clear();
		getdeep(root, root);
		for (int i = p.Begin[root]; i != -1; i = p.Next[i])
		{
			int L = p.to[i];
			if (vis[L] == false)
			{
				del_(L, root, L);
				calc2(L, root);
				//ins_(L, root);
				all_[L] = size1[L];
			}
		}
		for (int i = p.Begin[root]; i != -1; i = p.Next[i])
			if (vis[p.to[i]] == false)
			{
				root = 0;
				allnode = all_[p.to[i]];
				calc(p.to[i]);
			}
	}
	void init(int n)
	{
		memset(vis, 0, sizeof(vis));
		memset(size1, 0, sizeof(size1));
		memset(size2, 0, sizeof(size2));
		root = 0;
		p.init_graph();
		allnode = n;
		size2[0] = n + 10;
	}
}
using namespace tree_split2;
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, u, v;
	cin >> n >> k;
	p.init_graph();
	init(n);
	ans = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		cin >> u >> v;
		p.add(u, v, 1), p.add(v, u, 1);
	}
	calc(1);
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cassert>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
using namespace std;
const int MAXN=2e5+5;
vector<int> v[MAXN];
int n,k,root,tot,vis[MAXN],siz[MAXN],mmax[MAXN];
int dep[MAXN],sum[MAXN],sz;
long long ans1,ans2;
inline int read()
{
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x;
}
template <typename T>
inline void Max(T &x,T y)
{
	if(x<y) x=y;
}
void dfs_root(int x,int fa)
{
	siz[x]=1,mmax[x]=0;
	for(auto y:v[x])
	{
		if(y==fa||vis[y])
			continue;
		dfs_root(y,x);
		siz[x]+=siz[y];
		Max(mmax[x],siz[y]);
	}
	Max(mmax[x],tot-siz[x]);
	if(mmax[x]<mmax[root]) root=x;
}
inline void dfs_dep(int x,int fa)
{
	dep[x]=dep[fa]+1;
	for(auto y:v[x])
		if(!vis[y]&&y!=fa)
			dfs_dep(y,x);
}
void dfs_chg(int x,int fa,int opt)
{
	sz+=opt;
	int dis=dep[x];
	sum[dis%k]+=opt;
	for(auto y:v[x])
		if(!vis[y]&&y!=fa)
			dfs_chg(y,x,opt);
}
void dfs_calc(int x,int fa)
{
	int dis=dep[x];
	ans1+=1ll*sz*(dis/k); dis%=k;
	for(int i=0;i<=k-dis;i++)
		if(i||dis)
			ans2+=sum[i];
	for(int i=k-dis+1;i<k;i++)
		ans2+=(sum[i]<<1);
	for(auto y:v[x])
		if(!vis[y]&&y!=fa)
			dfs_calc(y,x);
}
inline void clear()
{
	sz=0,ans2=0;
	for(int i=0;i<k;i++)
		sum[i]=0;
}
inline void calc(int x)
{
	sz=1,dep[x]=0;
	for(auto y:v[x])
		if(!vis[y])
			dfs_dep(y,x);
	for(auto y:v[x])
		if(!vis[y])
			dfs_chg(y,x,1);
	for(auto y:v[x])
	{
		if(vis[y])
			continue;
		dfs_chg(y,x,-1);
		dfs_calc(y,x);
		dfs_chg(y,x,1);
	}
	for(int i=1;i<k;i++)
		ans1+=sum[i];
	assert(!(ans2&1));
	ans1+=ans2/2,clear();
// 	clog<<ans1<<' '<<x<<endl;
}
void devide_conquer(int x)
{
// 	clog<<x<<endl;
	vis[x]=1,calc(x);
	for(auto y:v[x])
	{
		if(vis[y]) continue;
		root=0,tot=siz[y];
		mmax[root]=0x3f3f3f3f;
		dfs_root(y,x);
		devide_conquer(root);
	}
}
int main()
{
	n=read(),k=read();
	for(int i=2;i<=n;i++)
	{
		int x=read(),y=read();
		v[x].push_back(y);
		v[y].push_back(x);
	}
	root=0,tot=n;
	mmax[root]=0x3f3f3f3f;
	dfs_root(1,0);
	devide_conquer(root);
	cout<<ans1<<endl;
	return 0;
}


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

int n;
int k;
int dp[5][5];
int summma = 0;
vector<vector<int>> g;
vector<int> dfs(int v, int h, int p = -1)
{
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            summma += ((k - i) % k * (dp[j][(2 * j - (h % k) + i + k) % k]));
        }
    }
    vector<int> summa(k);
    summa[h % k]++;
    dp[h % k][h % k]++;
    for (int i = 0; i < g[v].size(); i++)
    {
        if (g[v][i] != p)
        {
            vector<int> tmp = dfs(g[v][i], h + 1, v);
            for (int j = 0; j < k; j++)
            {
                summa[j] += tmp[j];
                dp[h % k][j] += tmp[j];
            }
        }
    }
    for (int i = 0; i < k; i++)
    {
        dp[h % k][i] -= summa[i];
    }
    return summa;
}
int countik = 0;
int dfs1(int v, int p)
{
    int summar = 0;
    for (int i = 0; i < g[v].size(); i++)
    {
        if (g[v][i] != p)
        {
            int tmp = dfs1(g[v][i], v);
            countik += tmp * (n - tmp);
            summar += tmp;
        }
    }
    return summar + 1;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    g.resize(n);
    for (int i = 0; i < n - 1; i++)
    {
        int v, u;
        cin >> v >> u;
        g[v - 1].push_back(u - 1);
        g[u - 1].push_back(v - 1);
    }
    dfs(0, 0);
     dfs1(0, 0);
    int uu = n * (n - 1) / 2;
    countik += (summma);
    cout << countik / k;
}


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

int n;
int k;
int dp[5][5];
int summma = 0;
vector<vector<int>> g;
vector<int> dfs(int v, int h, int p = -1)
{
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < k; j++)
        {
            summma += ((k - i) % k * (dp[j][(2 * j - h + i + k) % k]));
        }
    }
    vector<int> summa(k);
    summa[h % k]++;
    dp[h % k][h % k]++;
    for (int i = 0; i < g[v].size(); i++)
    {
        if (g[v][i] != p)
        {
            vector<int> tmp = dfs(g[v][i], h + 1, v);
            for (int j = 0; j < k; j++)
            {
                summa[j] += tmp[j];
                dp[h % k][j] += tmp[j];
            }
        }
    }
    for (int i = 0; i < k; i++)
    {
        dp[h % k][i] -= summa[i];
    }
    return summa;
}
int countik = 0;
int dfs1(int v, int p)
{
    int summar = 0;
    for (int i = 0; i < g[v].size(); i++)
    {
        if (g[v][i] != p)
        {
            int tmp = dfs1(g[v][i], v);
            countik += tmp * (n - tmp);
            summar += tmp;
        }
    }
    return summar + 1;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    g.resize(n);
    for (int i = 0; i < n - 1; i++)
    {
        int v, u;
        cin >> v >> u;
        g[v - 1].push_back(u - 1);
        g[u - 1].push_back(v - 1);
    }
    dfs(0, 0);
    dfs1(0, 0);
    int uu = n * (n - 1) / 2;
    countik += (summma);
    cout << countik / k;
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, 10 * depth);
					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ( ( (a % k) - (b % k) ) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, (2 * depth) % k);

					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					assert(needs < k);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


//Problem Link: http://codeforces.com/contest/771/problem/C
//Problem type: Dynamic Programming

//TODO 765E

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <stdio.h>
#include <queue>
#include <set>
#include <list>
#include <cmath>
#include <assert.h>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> //cout << setprecision(node) << fixed << num

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " ";

typedef long long int ll;
typedef long double ld;
typedef std::pair <int, int> ii;
typedef std::vector <int> vi;
typedef std::vector <ll> vll;
const int INF = int(1e9);
const ll INF64 = ll(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;
using namespace std;

int N, K;
vector <vi> tree(200007);
ll ans = 0;
int total_subtree[200007], distance_mod[200007][5], parent[200007];
void dfs(int curr, int papa, int depth) {
    parent[curr] = papa;
    total_subtree[curr] = distance_mod[curr][depth % K] = 1;
    for (int adj : tree[curr]) {
        if (adj != papa) {
            dfs(adj, curr, depth+1);
            for (int i = 0; i < K; i++) {
                for (int j = 0; j < K; j++) {
                    int rem = (i + j - 2 * depth) % K;
                    if (rem < 0) rem += K;
                    assert(K > rem);
                    int need = (K - rem) % K;
                    ans += (ll) need * distance_mod[curr][i] * distance_mod[adj][j];
                }
            }
            for (int i = 0; i < K; i++) {
                distance_mod[curr][i] += distance_mod[adj][i];
            }
            total_subtree[curr] += total_subtree[adj];
        }
    }
    ans += (ll) total_subtree[curr] * (N - total_subtree[curr]);
}

int main() {
    int a,b;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N-1; i++) {
        scanf("%d %d", &a, &b);
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(1, 0, 0);
    cout << ans / K << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, (2 * depth) % k);
					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					assert(needs < k);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


//Problem Link: http://codeforces.com/contest/771/problem/C
//Problem type: Dynamic Programming

//TODO 765E

#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <stdio.h>
#include <queue>
#include <set>
#include <list>
#include <cmath>
#include <assert.h>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> //cout << setprecision(node) << fixed << num

#define mp make_pair
#define pb push_back
#define x first
#define y second
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " ";

typedef long long int ll;
typedef long double ld;
typedef std::pair <int, int> ii;
typedef std::vector <int> vi;
typedef std::vector <ll> vll;
const int INF = int(1e9);
const ll INF64 = ll(1e18);
const ld EPS = 1e-9, PI = 3.1415926535897932384626433832795;
using namespace std;

int N, K;
vector <vi> tree(200007);
int ans = 0;
int total_subtree[200007], distance_mod[200007][5], parent[200007];
void dfs(int curr, int papa, int depth) {
    parent[curr] = papa;
    total_subtree[curr] = distance_mod[curr][depth % K] = 1;
    for (int adj : tree[curr]) {
        if (adj != papa) {
            dfs(adj, curr, depth+1);
            for (int i = 0; i < K; i++) {
                for (int j = 0; j < K; j++) {
                    int rem = (i + j - 2 * depth) % K;
                    if (rem < 0) rem += K;
                    assert(K > rem);
                    int need = (K - rem) % K;
                    ans += need * distance_mod[curr][i] * distance_mod[adj][j];
                }
            }
            for (int i = 0; i < K; i++) {
                distance_mod[curr][i] += distance_mod[adj][i];
            }
            total_subtree[curr] += total_subtree[adj];
        }
    }
    ans += total_subtree[curr] * (N - total_subtree[curr]);
}

int main() {
    int a,b;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N-1; i++) {
        scanf("%d %d", &a, &b);
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(1, 0, 0);
    cout << ans / K << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					if (i + j < 2 * depth) continue;
					int remainder = subtract(i + j, 2 * depth);
					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, (2 * depth) % k);
					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, 2 * depth);
					// compute x such that (distance + x) is divisible by k
					int needs = k - remainder;
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	int ret = ( (a % k) - (b % k) ) % k;
	if (ret < 0) ret += k;
	return ret;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, (2 * depth) % k);

					// compute x such that (distance + x) is divisible by k
					int needs = subtract(k, remainder);
					assert(needs < k);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, 2 * depth);
					// compute x such that (distance + x) is divisible by k
					if (remainder < 0) continue;
					int needs = subtract(k, remainder);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5 + 5;
vector<int> edges[nax];
int count_subtree[nax][5];
int total_subtree[nax];
long long answer;
int n, k;

int subtract(int a, int b) {
	return ((a - b) % k + k) % k;
}

void dfs(int a, int par, int depth) {
	count_subtree[a][depth % k] = total_subtree[a] = 1;
	for(int b : edges[a])
		if(b != par) {
			dfs(b, a, depth + 1);
			for(int i = 0; i < k; ++i)
				for(int j = 0; j < k; ++j) {
					// compute distance modulo k
					int remainder = subtract(i + j, 2 * depth);
					// compute x such that (distance + x) is divisible by k
					assert(remainder > 0);
					int needs = subtract(k, remainder);
					answer += (long long) needs
							* count_subtree[a][i] * count_subtree[b][j];
				}
			for(int i = 0; i < k; ++i)
				count_subtree[a][i] += count_subtree[b][i];
			total_subtree[a] += total_subtree[b];
		}
	// in how many pairs we will count the edge from 'a' to its parent?
	answer += (long long) total_subtree[a] * (n - total_subtree[a]);
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(1, -1, 0);
	assert(answer % k == 0);
	printf("%lld\n", answer / k);
}


// P6.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
using namespace std;

#ifdef MSVC
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#endif

vector<int> adjList[100010];
int N, K;
long long int ans = 0;

// #occurances, total jumps
vector< pair<long long, long long> > dfs(int u, int p) {

	vector< pair<long long, long long> > ret(K);
	for (int i = 0; i < K; i++) ret[i] = make_pair(0, 0);
	ret[0].first += 1;
	for (auto v : adjList[u]) {
		if (v == p) continue;
		auto x = dfs(v, u);
		x[0].second += x[0].first;
		rotate(x.begin(), --x.end(), x.end());

		// Cross branch jumps
		for (int i = 0; i < K; i++) for (int j = 0; j < K; j++) {
			if (i == 0 || j == 0 || i + j > K) ans += ret[i].first * x[j].second + ret[i].second * x[j].first;
			else ans += ret[i].first * x[j].second + ret[i].second * x[j].first - ret[i].first * x[j].first;
		}

		// Accumulate the jumps
		for (int i = 0; i < K; i++) {
			ret[i].first += x[i].first;
			ret[i].second += x[i].second;
		}

	}

	return ret;
}

int main()
{

#ifdef MSVC
	freopen("input.txt", "r", stdin);
#endif

	cin >> N >> K;
	for (int i = 1; i < N; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	dfs(0, -1);
	cout << ans << endl;
    return 0;
}


// P6.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#ifdef MSVC
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#endif

vector<int> adjList[200010];
int N, K;
long long int ans = 0;

// #occurances, total jumps
vector< pair<long long, long long> > dfs(int u, int p) {

	vector< pair<long long, long long> > ret(K);
	for (int i = 0; i < K; i++) ret[i] = make_pair(0, 0);
	ret[0].first += 1;
	for (auto v : adjList[u]) {
		if (v == p) continue;
		auto x = dfs(v, u);
		x[0].second += x[0].first;
		rotate(x.begin(), --x.end(), x.end());

		// Cross branch jumps
		for (int i = 0; i < K; i++) for (int j = 0; j < K; j++) {
			if (i == 0 || j == 0 || i + j > K) ans += ret[i].first * x[j].second + ret[i].second * x[j].first;
			else ans += ret[i].first * x[j].second + ret[i].second * x[j].first - ret[i].first * x[j].first;
		}

		// Accumulate the jumps
		for (int i = 0; i < K; i++) {
			ret[i].first += x[i].first;
			ret[i].second += x[i].second;
		}

	}

	return ret;
}

int main()
{

#ifdef MSVC
	freopen("input.txt", "r", stdin);
#endif

	cin >> N >> K;
	for (int i = 1; i < N; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	dfs(0, -1);
	cout << ans << endl;
    return 0;
}


// P6.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#ifdef MSVC
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4996)
#endif

vector<int> adjList[100010];
int N, K;
long long int ans = 0;

// #occurances, total jumps
vector< pair<long long, long long> > dfs(int u, int p) {

	vector< pair<long long, long long> > ret(K);
	for (int i = 0; i < K; i++) ret[i] = make_pair(0, 0);
	ret[0].first += 1;
	for (auto v : adjList[u]) {
		if (v == p) continue;
		auto x = dfs(v, u);
		x[0].second += x[0].first;
		rotate(x.begin(), --x.end(), x.end());

		// Cross branch jumps
		for (int i = 0; i < K; i++) for (int j = 0; j < K; j++) {
			if (i == 0 || j == 0 || i + j > K) ans += ret[i].first * x[j].second + ret[i].second * x[j].first;
			else ans += ret[i].first * x[j].second + ret[i].second * x[j].first - ret[i].first * x[j].first;
		}

		// Accumulate the jumps
		for (int i = 0; i < K; i++) {
			ret[i].first += x[i].first;
			ret[i].second += x[i].second;
		}

	}

	return ret;
}

int main()
{

#ifdef MSVC
	freopen("input.txt", "r", stdin);
#endif

	cin >> N >> K;
	for (int i = 1; i < N; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
	}
	dfs(0, -1);
	cout << ans << endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rep0(i, n) for(int i = (0); i < (n); i++)
#define repd(i,m,n) for(int i=(m); i > (n); i--)
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plli pair<pll,int>
#define mp make_pair
#define endl '\n'
#define pb push_back
#define x first
#define y second
#define pt pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpll vector<pll>
#define vpt vector<pt>
#define pdd pair<double, double>
#define vpdd vector<pair<double, double> >
#define pq priority_queue
//#define _USE_MATH_DEFINES
using namespace std;
vvi g;
vvll dp, ams;
int n, k;
void dfs(int v, int p) {
	ams[k - 1][v]++;
	for (auto& el : g[v]) {
		if (el == p) {
			continue;
		}
		dfs(el, v);

	//	dp[1 % k][v]++;

		for (int i = 0; i < k - 1; ++i) {
			dp[(i + 1) % k][v] += dp[i][el] ;
		}

		dp[0][v] += dp[k - 1][el] + ams[k - 1][el];
		for (int i = 0; i < k; ++i) {
			ams[(i + 1) % k][v] += ams[i][el];
		}
	}
}

ll sum = 0;
void dfs2(int v, int p, vll outer, vll amOut) {
	for (int i = 0; i < k; ++i) {
		sum += outer[i] + dp[i][v];
	}

	for (auto& el : g[v]) {
		if (el == p)
			continue;
		vll nouter(k), namOut(k);

		for (int i = 0; i < k - 1; ++i) {
			ll childPath = ams[i][v] - ams[(i + k - 1) % k][el];
			ll prevPart = dp[(i + k - 1) % k][el];
			if (i == 0) {
				prevPart += ams[(i + k - 1) % k][el];
			}

			namOut[(i + 1) % k] += childPath;
			namOut[(i + 1) % k] += amOut[i];
			nouter[(i + 1) % k] += outer[i];
			nouter[(i + 1) % k] += dp[(i) % k][v] - prevPart;
		}

		ll childPath = ams[k - 1][v] - ams[(k + k - 2) % k][el];
		ll prevPart = dp[(k + k - 2) % k][el];
		if (k == 1) {
			prevPart += ams[0][el];
		}

		namOut[0] += childPath;
		namOut[0] += amOut[k - 1];
		nouter[0] += outer[k - 1] + amOut[k - 1];
		nouter[0] += dp[k - 1][v] - prevPart + childPath;

		dfs2(el, v, nouter, namOut);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> k;
	g.resize(n);
	dp.assign(k, vll(n));
	ams.assign(k, vll(n));
	rep0(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs(0, -1);
	dfs2(0, -1, vll(k), vll(k));
	cout << sum / 2 << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
#include<map>
#include<iterator>
#include<set>
#include<stack>
#include<queue>
#include<fstream>
#include<iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include<cmath>
#include<list>
#include <sstream>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rep0(i, n) for(int i = (0); i < (n); i++)
#define repd(i,m,n) for(int i=(m); i > (n); i--)
#define ll long long
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plli pair<pll,int>
#define mp make_pair
#define endl '\n'
#define pb push_back
#define x first
#define y second
#define pt pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpll vector<pll>
#define vpt vector<pt>
#define pdd pair<double, double>
#define vpdd vector<pair<double, double> >
#define pq priority_queue
//#define _USE_MATH_DEFINES
using namespace std;
vvi g;
vvll dp, ams;
int n, k;
void dfs(int v, int p) {
	ams[k - 1][v]++;
	for (auto& el : g[v]) {
		if (el == p) {
			continue;
		}
		dfs(el, v);

	//	dp[1 % k][v]++;

		for (int i = 0; i < k - 1; ++i) {
			dp[(i + 1) % k][v] += dp[i][el] ;
		}

		dp[0][v] += dp[k - 1][el] + ams[k - 1][el];
		for (int i = 0; i < k; ++i) {
			ams[(i + 1) % k][v] += ams[i][el];
		}
	}
}

ll sum = 0;
void dfs2(int v, int p, vll outer, vll amOut) {
	for (int i = 0; i < k; ++i) {
		sum += outer[i] + dp[i][v];
	}

	for (auto& el : g[v]) {
		if (el == p)
			continue;
		vll nouter(k), namOut(k);

		for (int i = 0; i < k - 1; ++i) {
			ll childPath = ams[i][v] - ams[(i + k - 1) % k][el];
			ll prevPart = dp[(i + k - 1) % k][el];
			if (i == 0) {
				prevPart += ams[(i + k - 1) % k][el];
			}

			namOut[(i + 1) % k] += childPath;
			namOut[(i + 1) % k] += amOut[i];
			nouter[(i + 1) % k] += outer[i];
			nouter[(i + 1) % k] += dp[(i) % k][v] - prevPart;
		}

		ll childPath = ams[k - 1][v] - ams[(k + k - 2) % k][el];
		ll prevPart = dp[(k + k - 2) % k][el];
		if (k == 1) {
			prevPart += ams[0][el];
		}

		namOut[0] += childPath;
		namOut[0] += amOut[k - 1];
		nouter[0] += outer[k - 1] + amOut[k - 1];
		nouter[0] += dp[k - 1][v] - prevPart + childPath;

		dfs2(el, v, nouter, namOut);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	freopen("in.txt", "r", stdin);
	cin >> n >> k;
	g.resize(n);
	dp.assign(k, vll(n));
	ams.assign(k, vll(n));
	rep0(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfs(0, -1);
	dfs2(0, -1, vll(k), vll(k));
	cout << sum / 2 << endl;
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define forn(i, n) for(int i=0;i<(n);++i)
#define clr(ar, val) memset(ar, val, sizeof(ar))

using namespace std;

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<ld, ld> point;

const int MAXN = 2e5 + 200;
const int INF = int(1e9) + 7;
const long long LINF = 1ll * INF * INF;
const int md = int(1e9) + 7;
const ld eps = 1e-9;
const ld PI = 3.1415926535897932384626433832795l;

int n, k;
long long dp[MAXN][6], cnt[MAXN][6], sum_dp[6], sum_cnt[6], ans;
vector<vector<int>> g(MAXN);

void dfs(int v, int pr) {
    for (int u : g[v]) {
        if (u != pr) {
            dfs(u, v);
            for (int i = 0; i < k; i++) {
                ans += dp[u][i] + cnt[u][i];
                cout << "add " << v << " " << u << " " << dp[u][i] + cnt[u][i] << endl;

                cnt[v][(i + 1) % k] += cnt[u][i];
                if (i < k - 1) {
                    dp[v][i + 1] += dp[u][i];
                } else {
                    dp[v][0] += dp[u][k - 1] + cnt[u][k - 1];
                }
            }
        }
    }

    cnt[v][0]++;

    //for (int i = 0; i < k; i++) {
    //    cout << "cnt " << v << " " << i << " " << cnt[v][i] << endl;
    //}

    long long add = 0;
    clr(sum_dp, 0);
    clr(sum_cnt, 0);
    for (int u : g[v]) {
        if (u == pr) {
            continue;
        }
        for (int j = 0; j < k; j++) {
            sum_dp[j] += dp[u][j];
            sum_cnt[j] += cnt[u][j];
        }
    }

    //for (int i = 0; i < k; i++) {
    //    cout << v << " " << sum_dp[i] << " " << sum_cnt[i] << endl;
    //}
    //cout << endl;

    for (int u : g[v]) {
        if (u == pr) {
            continue;
        }
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < k; j++) {
                long long val_dp = sum_dp[j] - dp[u][j];
                long long val_cnt = sum_cnt[j] - cnt[u][j];
                long long delta = val_cnt * dp[u][i] + val_dp * cnt[u][i] + val_cnt * cnt[u][i] * ((i + j + k + 1) / k);
                if (delta) {
                    add += delta;
                    //cout << "delta " << v << " " << u << " " << i << " " << j << " " << delta << endl;
                }
            }
        }
    }
    assert(add % 2 == 0);
    ans += add / 2;

    cout << v << " " << (add / 2) << endl;
}

int main()
{
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(1, 0);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define forn(i, n) for(int i=0;i<(n);++i)
#define clr(ar, val) memset(ar, val, sizeof(ar))

using namespace std;

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<ld, ld> point;

const int MAXN = int(2e5) + 200;
const int INF = int(1e9) + 10;
const long long LINF = 1LL * INF * INF;
const int md = int(1e9) + 7;
const ld eps = 1e-9;
const ld PI = 3.1415926535897932384626433832795l;

int n;

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
#define forn(i, n) for(int i=0;i<(n);++i)
#define clr(ar, val) memset(ar, val, sizeof(ar))

using namespace std;

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<ld, ld> point;

const int MAXN = 2e5 + 200;
const int INF = int(1e9) + 7;
const long long LINF = 1ll * INF * INF;
const int md = int(1e9) + 7;
const ld eps = 1e-9;
const ld PI = 3.1415926535897932384626433832795l;

int n, k;
long long dp[MAXN][6], cnt[MAXN][6], sum_dp[6], sum_cnt[6], ans;
vector<vector<int>> g(MAXN);

void dfs(int v, int pr) {
    for (int u : g[v]) {
        if (u != pr) {
            dfs(u, v);
            for (int i = 0; i < k; i++) {
                ans += dp[u][i] + cnt[u][i];
                //cout << "add " << v << " " << u << " " << dp[u][i] + cnt[u][i] << endl;

                cnt[v][(i + 1) % k] += cnt[u][i];
                if (i < k - 1) {
                    dp[v][i + 1] += dp[u][i];
                } else {
                    dp[v][0] += dp[u][k - 1] + cnt[u][k - 1];
                }
            }
        }
    }

    cnt[v][0]++;

    //for (int i = 0; i < k; i++) {
    //    cout << "cnt " << v << " " << i << " " << cnt[v][i] << endl;
    //}

    long long add = 0;
    clr(sum_dp, 0);
    clr(sum_cnt, 0);
    for (int u : g[v]) {
        if (u == pr) {
            continue;
        }
        for (int j = 0; j < k; j++) {
            sum_dp[j] += dp[u][j];
            sum_cnt[j] += cnt[u][j];
        }
    }

    //for (int i = 0; i < k; i++) {
    //    cout << v << " " << sum_dp[i] << " " << sum_cnt[i] << endl;
    //}
    //cout << endl;

    for (int u : g[v]) {
        if (u == pr) {
            continue;
        }
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < k; j++) {
                long long val_dp = sum_dp[j] - dp[u][j];
                long long val_cnt = sum_cnt[j] - cnt[u][j];
                long long delta = val_cnt * dp[u][i] + val_dp * cnt[u][i] + val_cnt * cnt[u][i] * ((i + j + k + 1) / k);
                if (delta) {
                    add += delta;
                    //cout << "delta " << v << " " << u << " " << i << " " << j << " " << delta << endl;
                }
            }
        }
    }
    assert(add % 2 == 0);
    ans += add / 2;

    //cout << v << " " << (add / 2) << endl;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a].pb(b);
        g[b].pb(a);
    }

    dfs(1, 0);

    cout << ans << endl;
    return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+30;
vector<int>v[maxn];
int n, k, h[maxn];
LL ans = 0, dp[maxn][5];
void dfs(int cur, int pre, int d)
{
    h[cur] = 1;
    dp[cur][d%k] = 1;
    for(auto to :v[cur])
    {
        if(to == pre) continue;
        dfs(to, cur, d+1);
        for(int i=0; i<k; ++i)
        {
            for(int j=0; j<k; ++j)
            {
                int x = (i+j-d*2)%k;//经过以cur为根节点的两点LCA。
                int y = (k-x)%k;//差多少才能被k整除。
                ans += y*dp[cur][i]*dp[to][j];
            }
        }
        for(int i=0; i<k; ++i)
            dp[cur][i] += dp[to][i];
        ans += (n-h[to])*h[to];//计算树的两两距离（相当于累加这些边的贡献次数）。
        h[cur] += h[to];
    }

}
int main()
{
    int a, b;
    scanf("%d%d",&n,&k);
    for(int i=1; i<n; ++i)
    {
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,0,0);
    printf("%lld\n",ans/k);
    return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+30;
vector<int>v[maxn];
int n, k;
LL ans = 0, dp[maxn][5],h[maxn];
void dfs(int cur, int pre, int d)
{
    h[cur] = 1;
    dp[cur][d%k] = 1;
    for(auto to :v[cur])
    {
        if(to == pre) continue;
        dfs(to, cur, d+1);
        for(int i=0; i<k; ++i)
        {
            for(int j=0; j<k; ++j)
            {
                int x = (i+j-d*2)%k;//经过以cur为根节点的两点LCA。
                int y = (k-x)%k;//差多少才能被k整除。
                ans += y*dp[cur][i]*dp[to][j];
            }
        }
        for(int i=0; i<k; ++i)
            dp[cur][i] += dp[to][i];
        ans += (n-h[to])*h[to];//计算树的两两距离（相当于累加这些边的贡献次数）。
        h[cur] += h[to];
    }

}
int main()
{
    int a, b;
    scanf("%d%d",&n,&k);
    for(int i=1; i<n; ++i)
    {
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,0,0);
    printf("%lld\n",ans/k);
    return 0;
}


# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5+30;
vector<int>v[maxn];
int n, k,;
LL ans = 0, dp[maxn][5],h[maxn];
void dfs(int cur, int pre, int d)
{
    h[cur] = 1;
    dp[cur][d%k] = 1;
    for(auto to :v[cur])
    {
        if(to == pre) continue;
        dfs(to, cur, d+1);
        for(int i=0; i<k; ++i)
        {
            for(int j=0; j<k; ++j)
            {
                int x = (i+j-d*2)%k;//经过以cur为根节点的两点LCA。
                int y = (k-x)%k;//差多少才能被k整除。
                ans += y*dp[cur][i]*dp[to][j];
            }
        }
        for(int i=0; i<k; ++i)
            dp[cur][i] += dp[to][i];
        ans += (n-h[to])*h[to];//计算树的两两距离（相当于累加这些边的贡献次数）。
        h[cur] += h[to];
    }

}
int main()
{
    int a, b;
    scanf("%d%d",&n,&k);
    for(int i=1; i<n; ++i)
    {
        scanf("%d%d",&a,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,0,0);
    printf("%lld\n",ans/k);
    return 0;
}