#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int >
#define pll pair<long long ,long long >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > >
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
//#define int long long

const long long  md = 1e9 + 7;
const int Inf = 1e9;
const ll Inf64 = 1e18;
const ll MaxN = 200001;
const ll MaxM = 1000001;
const ld eps = 1e-15;

using namespace std;

struct Vert {

	Vert() {
		w = 0;
		p = 0;
		end = false;
		was = false;
		for (int i = 0;i < 26;i++) {
			next[i] = NULL;
		}
	}

	Vert * next[26];
	ll w;
	ll p;
	bool  end;
	bool was;

};
bool ISOK(char c) {
	if ((c >= 'a' && c <= 'z') ) {
		return true;
	}
	else return false;
}
signed main() {
	ios_base::sync_with_stdio(0);
	//ifstream cin("flashmob.in");
	//ofstream cout("flashmob.out");
	cin.tie(0);
	cout.tie(0);
	// //
	//cout << fixed,cout.precision(10);
	// //
	//ifstream cin("input.txt");
	string Text;
	while (!cin.eof()) {
		string s;
		getline(cin, s);
		Text +=  s + '\n';
	}
	Text.pop_back();
	if (ISOK((char)Text.back()))Text.push_back('\n');

	bool New = false;
	Vert *St = new Vert();
	Vert *Now = St;
	ll Ans = 0;
	ll t = 0;
	ll r = 0;
	ll e = 0;
	bool f = true;
	for (char c : Text) {

		if (ISOK(c)) {

			ll k;
			if ((c >= 'a' && c <= 'z')) k = c - 'a';

			if (Now->next[k] == NULL) {

				Now->next[k] = new Vert();

				Now->p++;

				if (Now->end == true) {
					Now->end = false;
					Now->was = true;
				}
				if (Now->end && Now->p == 0 && f) {
					Ans -= (r - e - 2 > 0 ? r - e - 2 : 0);
					e = 0;
					f = false;
				}
				f = false;

			}
			if (Now->p > 1 || Now->was) {
				e = r;
			}
			Ans++;

			r++;

			Now = Now->next[k];
			if (Now->end && Now->p == 0 && f) {
				Ans -= (r - e-2 > 0? r - e - 2:0);
				e = 0;
				f = false;
			}
		}
		else {

			//New = true;
			Ans += 1;
			e = 0;
			f = true;
			if(Now->p == 0)
			Now->end = true;
			else Now->was = true;
			Now = St;
			//New = false;
			r = 0;
			e = 0;
		}
		t++;

	}
	cout << Ans ;
	/// ///////////////
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';

	return 0;

}
/*

*/


#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int >
#define pll pair<long long ,long long >
#define pbb pair<bool,bool>
#define plll pair<long long,pair<long long ,long long > >
#define sefi second.first
#define sese second.second
#define fi first
#define se second
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
//#define int long long

const long long  md = 1e9 + 7;
const int Inf = 1e9;
const ll Inf64 = 1e18;
const ll MaxN = 200001;
const ll MaxM = 1000001;
const ld eps = 1e-15;

using namespace std;

struct Vert {

	Vert() {
		w = 0;
		p = 0;
		end = false;
		was = false;
		for (int i = 0;i < 26;i++) {
			next[i] = NULL;
		}
	}

	Vert * next[26];
	ll w;
	ll p;
	bool  end;
	bool was;

};
bool ISOK(char c) {
	if ((c >= 'a' && c <= 'z') ) {
		return true;
	}
	else return false;
}
signed main() {
	ios_base::sync_with_stdio(0);
	//ifstream cin("flashmob.in");
	//ofstream cout("flashmob.out");
	cin.tie(0);
	cout.tie(0);
	// //
	//cout << fixed,cout.precision(10);
	// //
	//ifstream cin("input.txt");
	string Text;
	while (!cin.eof()) {
		string s;
		getline(cin, s);
		Text +=  s + '\n';
	}
	Text.pop_back();
	if (ISOK((char)Text.back()))Text.push_back('\n');

	bool New = false;
	Vert *St = new Vert();
	Vert *Now = St;
	ll Ans = 0;
	ll t = 0;
	ll r = 0;
	ll e = 0;
	bool f = true;
	for (char c : Text) {

		if (ISOK(c)) {
			//if (New) {

			//}

			ll k;
			if ((c >= 'a' && c <= 'z')) k = c - 'a';

			//r = 1;

			if (Now->next[k] == NULL) {

				Now->next[k] = new Vert();

				Now->p++;
				//Now->end = false;
				if (Now->end == true) {
					Now->end = false;
					Now->was = true;
				}
				//Now->next[k]->end = true;
				e = 0;
				f = false;

			}
			if (Now->p > 1 || Now->was) {
				e = r;
			}
			Ans++;
			/*if (!ISOK(Text[t + 1])) {
				Now->end = true;
			}*/
			//e++;
			r++;

			Now = Now->next[k];
			if (Now->end && Now->p == 0 && f) {
				Ans -= (r - e-2 > 0? r - e - 2:0);
				e = 0;
				f = false;
			}
		}
		else {

			//New = true;
			Ans += 1;
			e = 0;
			f = true;
			Now->end = true;
			Now = St;
			//New = false;
			r = 0;
			e = 0;
		}
		t++;

	}
	cout << Ans ;
	/// ///////////////
	cerr << '\n' << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << '\n';

	return 0;

}
/*

*/


#include <iostream>
#include <string>

struct trie
{
    trie* children[26] = {};
    std::string* suggestion = nullptr;
};

trie* root = new trie();

int get_required_types(const std::string& str)
{

    trie* t = root;
    std::string* copy = nullptr;
    int min = -1;

    for(int i = 0; i < str.length(); ++i)
    {
        char c = str.at(i);
        int idx = c - 'a';
        if(t->children[idx] == nullptr)
        {
            t->children[idx] = new trie();
            if(copy == nullptr)
            {
                copy = new std::string(str);
            }

            t->children[idx]->suggestion = copy;
        }
        else
        {
            std::string* suggestion = t->children[idx]->suggestion;
            if(suggestion != nullptr)
            {
                if(min == -1 && str.find(*suggestion) == 0)
                {
                    min = ((i + 1) + 1) + (str.length() - suggestion->length());
                }
                if (str == *suggestion)
                {
                    break;
                }
                else
                {
                    t->children[idx]->suggestion = nullptr;
                }
            }
        }

        t = t->children[idx];
    }

    if(min == -1)
    {
        return str.length();
    }
    return std::min(min, (int)str.length());
}

int main()
{
    std::string row;
    int cnt = 0;

    while(std::getline(std::cin, row))
    {
        if(row.length() == 0)
        {
            break;
        }

        int start = 0;
        int end = 0;
        while(end < row.length())
        {
            char c = row.at(end);
            switch(c)
            {
                case ' ':
                case '.':
                case ',':
                case '?':
                case '!':
                case '\'':
                case '-':
                    if(start != end)
                    {
                        std::string s = row.substr(start, end - start);
                        cnt += get_required_types(s);
                    }
                    cnt += 1;
                    start = end + 1;
                    break;
                default:
                    break;
            }

            end += 1;
        }

        if(start != end)
        {
            std::string s = row.substr(start, end - start + 1);
            cnt += get_required_types(s);
        }

        cnt += 1; // newline
    }

//    cnt -= 1; // no newline at the end

    std::cout << cnt << std::endl;

    return 0;
}


#include <iostream>
#include <string>

struct trie
{
    trie* children[26] = {};
    std::string* suggestion = nullptr;
};

trie* root = new trie();

bool startswith(const std::string& orig, const std::string& pattern) {
    if (pattern.length() > orig.length()) {
        return false;
    }
    for (int i = 0; i < pattern.length(); ++i)
    {
        if (pattern[i] != orig[i])
        {
            return false;
        }
    }

    return true;
}

int get_required_types(const std::string& str)
{
    trie* t = root;
    std::string* copy = nullptr;
    int min = -1;
    bool force_clear = false;

    for(int i = 0; i < str.length(); ++i)
    {
        char c = str.at(i);
        int idx = c - 'a';
        if(t->children[idx] == nullptr)
        {
            t->children[idx] = new trie();
            if(copy == nullptr)
            {
                copy = new std::string(str);
            }

            t->children[idx]->suggestion = copy;
        }
        else
        {
            std::string* suggestion = t->children[idx]->suggestion;
            if(suggestion != nullptr)
            {
                if (force_clear)
                {
                    t->children[idx]->suggestion = nullptr;
                }
                else
                {
                    if(min == -1 && startswith(str, *suggestion))
                    {
                        min = ((i + 1) + 1) + (str.length() - suggestion->length());
                        if (str.length() == suggestion->length())
                        {
                            break;
                        }
                        force_clear = true;
                    }
                    t->children[idx]->suggestion = nullptr;
                }
            }
        }

        t = t->children[idx];
    }

    if(min == -1)
    {
        return str.length();
    }
    return std::min(min, (int)str.length());
}

int main()
{
    std::string row;
    int cnt = 0;

    while(std::getline(std::cin, row))
    {
        if(row.length() == 0)
        {
            break;
        }

        int start = 0;
        int end = 0;
        while(end < row.length())
        {
            char c = row.at(end);
            switch(c)
            {
                case ' ':
                case '.':
                case ',':
                case '?':
                case '!':
                case '\'':
                case '-':
                    if(start != end)
                    {
                        std::string s = row.substr(start, end - start);
                        cnt += get_required_types(s);
                    }
                    cnt += 1;
                    start = end + 1;
                    break;
                default:
                    break;
            }

            end += 1;
        }

        if(start != end)
        {
            std::string s = row.substr(start, end - start + 1);
            cnt += get_required_types(s);
        }

        cnt += 1; // newline
    }

//    cnt -= 1; // no newline at the end

    std::cout << cnt << std::endl;

    return 0;
}


#include <iostream>
#include <string>

struct trie
{
    trie* children[26] = {};
    std::string* suggestion = nullptr;
};

trie* root = new trie();

int first_distinct_char_index(int start_idx, const std::string& orig, const std::string& pattern) {
    while (start_idx < orig.length() && start_idx < pattern.length()) {
        if (orig[start_idx] != pattern[start_idx]) {
            return start_idx;
        }
        start_idx += 1;
    }

    return start_idx;
}

int get_required_types(const std::string& str)
{
    trie* t = root;
    std::string* copy = nullptr;
    int min = -1;

    for(int i = 0; i < str.length(); ++i)
    {
        char c = str.at(i);
        int idx = c - 'a';
        if(t->children[idx] == nullptr)
        {
            t->children[idx] = new trie();
            if(copy == nullptr)
            {
                copy = new std::string(str);
            }

            t->children[idx]->suggestion = copy;
        }
        else
        {
            std::string* suggestion = t->children[idx]->suggestion;
            if(suggestion != nullptr)
            {
                if(min == -1)
                {
                    int first_distinct = first_distinct_char_index(i, str, *suggestion);
                    if(suggestion->length() == first_distinct)
                    {
                        // we have found a prefix
                        min = ((i + 1) + 1) + (str.length() - suggestion->length());

                        if(str.length() == first_distinct)
                        {
                            // they are the same
                            break;
                        }
                    }
                    t->children[idx]->suggestion = nullptr;
                    int j = i + 1;

                    while(j < first_distinct)
                    {
                        t = t->children[idx];
                        c = str.at(j);
                        idx = c - 'a';
                        t->children[idx]->suggestion = nullptr;
                        j += 1;
                    }
                    i = j - 1;
                }
            }
        }

        t = t->children[idx];
    }

    if(min == -1)
    {
        return str.length();
    }
    return std::min(min, (int)str.length());
}

int main()
{
    std::string row;
    int cnt = 0;

    while(std::getline(std::cin, row))
    {
        if(row.length() == 0)
        {
            break;
        }

        int start = 0;
        int end = 0;
        while(end < row.length())
        {
            char c = row.at(end);
            switch(c)
            {
                case ' ':
                case '.':
                case ',':
                case '?':
                case '!':
                case '\'':
                case '-':
                    if(start != end)
                    {
                        std::string s = row.substr(start, end - start);
                        cnt += get_required_types(s);
                    }
                    cnt += 1;
                    start = end + 1;
                    break;
                default:
                    break;
            }

            end += 1;
        }

        if(start != end)
        {
            std::string s = row.substr(start, end - start + 1);
            cnt += get_required_types(s);
        }

        cnt += 1; // newline
    }

//    cnt -= 1; // no newline at the end

    std::cout << cnt << std::endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define sz(x) ((int)(x.size()))
#define UM map
#define US set
#define X first
#define Y second
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

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

bool bookva(const char& c)
{
	return ((c >= 'a') && (c <= 'z'));
}

const int& M1 = 1000000007, P1 = 85782,
M2 = 1000000009, P2 = 67891;

int umn(const ll& a, const ll& b, const ll& m)
{
	return (a * b) % m;
}

int slo(const int& a, const int& b, const int& m)
{
	int c = a + b;
	return (c >= m ? c - m : c);
}

void add_visit(US<pii>& vis, const string& word)
{
	pii h(0, 0);
	int i = 0, n = sz(word), s1 = 1, s2 = 1;
	while (i < n)
	{
		h = pii(slo(h.X, umn(s1, word[i], M2), M1), slo(h.Y, umn(s2, word[i], M2), M2));
		s1 = umn(s1, P1, M1);
		s2 = umn(s2, P2, M2);
		vis.insert(h);
		++i;
	}
}

int dictionarify(vector<string>& words, UM<pii, int>& dict, US<pii>& vis, const string& word)
{
	pii h(0, 0);
	int i = 0, n = sz(word), s1 = 1, s2 = 1;
	while ((i < n) && ((vis.find(h) != vis.end()) && (dict.find(h) == dict.end())))
	{
		h = pii(slo(h.X, umn(s1, word[i], M2), M1), slo(h.Y, umn(s2, word[i], M2), M2));
		s1 = umn(s1, P1, M1);
		s2 = umn(s2, P2, M2);
		++i;
	}
	auto aut = dict.find(h);
	if (aut != dict.end())
	{
		int numb_u = aut->Y;
		int m = sz(words[numb_u]);
		int k = min(m, n);
		if (words[numb_u] == word)
			return min(n, i + 1);
		int numb_word = sz(words);
		words.push_back(word);
		dict.erase(aut);
		int j = i;
		while ((i < k) && (words[numb_u][i] == word[i]))
		{
			h = pii(slo(h.X, umn(s1, word[i], M2), M1), slo(h.Y, umn(s2, word[i], M2), M2));
			s1 = umn(s1, P1, M1);
			s2 = umn(s2, P2, M2);
			++i;
		}
		if (i == n)
		{
			h = pii(slo(h.X, umn(s1, words[numb_u][i], M2), M1), slo(h.Y, umn(s2, words[numb_u][i], M2), M2));
			dict.insert({ h, numb_u });
			return n;
		}
		else if (i == m)
		{
			h = pii(slo(h.X, umn(s1, word[i], M2), M1), slo(h.Y, umn(s2, word[i], M2), M2));
			dict.insert({ h, numb_word });
			add_visit(vis, word);
			int first_word = min(m, j + 1);
			return first_word + (n - m);
		}
		else
		{
			pii h1 = pii(slo(h.X, umn(s1, words[numb_u][i], M2), M1), slo(h.Y, umn(s2, words[numb_u][i], M2), M2));
			dict.insert({ h1, numb_u });
			h = pii(slo(h.X, umn(s1, word[i], M2), M1), slo(h.Y, umn(s2, word[i], M2), M2));
			dict.insert({ h, numb_word });
			add_visit(vis, word);
			return n;
		}
	}
	if (vis.find(h) == vis.end())
	{
		int numb_word = sz(words);
		words.push_back(word);
		dict.insert({ h, numb_word });
		add_visit(vis, word);
		return n;
	}
	return n;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s;
	int ans = 0;
	UM<pii, int> dict;
	vector<string> words;
	US<pii> vis;
	vis.insert({ 0, 0 });
	while (getline(cin, s))
	{
		++ans;
		int n = sz(s);
		for (int i = 0; i < n; ++i)
		if (bookva(s[i]))
		{
			string word(1, s[i]);
			int j = i;
			while (bookva(s[++j]))
				word.push_back(s[j]);
			ans += dictionarify(words, dict, vis, word);
			i = j - 1;
		}
		else
			++ans;
	}
	cout << ans << '\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
mt19937_64 rngll(rng());
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<int,ll>pil;
typedef pair<ll,ll>pll;
const int mn=2e5+10;
const ll mod=998244353;
string s;
int ans,sav;
bool nu;
struct nd{
    map<char,nd*>c;
    int num;
};
nd*rt=new nd();
void add(nd*n,int ind){
    if(ind==s.size()){
        if(n->num)sav=0;
        return;
    }
    if((n->num!=1||n==rt));
    else {
        sav++;
    }
    if(nu)n->num++;
    if(!n->c.count(s[ind]))n->c[s[ind]]=new nd();
    if(n->c.size()>1)sav=0;
    add(n->c[s[ind]],ind+1);

}
set<string>u;
int main(){
    cin>>noskipws;
    char c;
    while(cin>>c){
        if(c>='a'&&c<='z'){
            s.push_back(c);
        }
        else{
            ans++;
            if(!s.size())continue;
            nu=(u.find(s)==u.end());
            sav=0;
            ans+=s.size();
            add(rt,0);
            ans-=max(0,sav-1);
            s.clear();
        }
    }
    if(s.size()) {
        nu=(u.find(s)==u.end());
        sav=0;
        ans+=s.size();
        add(rt,0);
        ans-=max(0,sav-1);
        s.clear();
    }
    printf("%d",ans);
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a<=0)
   cout<<b/n+1+abs(a)/n;
   else
   cout<<(b-a+1)/n;
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a<=0 && b>0)
   cout<<b/n+1+abs(a)/n;
   else
   cout<<(b-a+1)/n;
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a>0 && b>0)
    cout<<b/n-(a-1)/n;
   else if(a<0 && b<0)
   cout<<abs(a)/n-(abs(b)-1)/n;
   else
   cout<<b/n+1+abs(a)/n;
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a<0)
   cout<<b/n+1+abs(a)/n;
   else
   cout<<(b-a+1)/n;
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a<=0 && b>=0)
   cout<<b/n+1+abs(a)/n;
   else
   cout<<(b-a+1)/n;
   return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ff first
#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define ll long long int
#define P pair<int,int>

using namespace std;

ll add(ll x,ll y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

ll mul(ll x,ll y)
{
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x,ll y)
{
    ll z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

ll inv(ll x)
{
    return binpow(x, MOD - 2);
}

ll divide(ll x,ll y)
{
    return mul(x, inv(y));
}

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

   ll n,a,b;
   cin>>n>>a>>b;

   if(a<=0 && b>=0)
   cout<<b/n+1+abs(a)/n;
   else
   cout<<abs(a)/n-(abs(b)-1)/n;
   return 0;
}


#include <bits/stdc++.h>
# define lli long long int
using namespace std;
//const int MOD = 1000000007;
int main()
{
    lli n,a=0,b=0,c=0,i,k,ans=0;
    cin>>k>>a>>b;
    if(a>=0 && b>=0)
    {
        ans=(b/k)-(a/k);
        if(a%k==0)
        ans++;
    }
    else if(a<0 && b>=0)
    {
        ans=abs(a)/k;
        ans+=b/k;
        ans++;
    }
    else if(a<0 && b<0)
    {
        ans=abs(a)/k-abs(b)/k;
        if(abs(a)%k==0 && a!=b)
        ans++;
    }
     cout<<ans<<endl;
return 0;
}


#include <bits/stdc++.h>
# define lli long long int
using namespace std;
//const int MOD = 1000000007;
int main()
{
    lli n,a=0,b=0,c=0,i,k,ans=0;
    cin>>k>>a>>b;
    if(a>=0 && b>=0)
    {
        ans=(b/k)-(a/k);
        if(a%k==0)
        ans++;
    }
    else if(a<0 && b>=0)
    {
        ans=abs(a)/k;
        ans+=b/k;
    }
    else if(a<0 && b<0)
    {
        ans=abs(a)/k-abs(b)/k;
        if(abs(a)%k==0)
        ans++;
    }
    if(0>=a && 0<=b)
    ans++;
     cout<<ans<<endl;

}


#include <bits/stdc++.h>
# define lli long long int
using namespace std;
//const int MOD = 1000000007;
int main()
{
    lli n,a=0,b=0,c=0,i,k,ans=0;
    cin>>k>>a>>b;
    if(a>=0 && b>=0)
    {
        ans=(b/k)-(a/k);
        if(a%k==0)
        ans++;
    }
    else if(a<0 && b>=0)
    {
        ans=abs(a)/k;
        ans+=b/k;
        ans--;
    }
    else if(a<0 && b<0)
    {
        ans=abs(a)/k-abs(b)/k;
        if(abs(a)%k==0 && a!=b)
        ans++;
    }
     cout<<ans<<endl;
return 0;
}


#include <bits/stdc++.h>
# define lli long long int
using namespace std;
//const int MOD = 1000000007;
int main()
{
    lli n,a=0,b=0,c=0,i,k,ans=0;
    cin>>k>>a>>b;
    if(a>=0 && b>=0)
    {
        ans=(b/k)-(a/k);
        if(a%k==0)
        ans++;
    }
    else if(a<0 && b>=0)
    {
        ans=abs(a)/k;
        ans+=b/k;
        ans++;
    }
    else if(a<0 && b<0)
    {
        ans=abs(a)/k-abs(b)/k;
        if(abs(b)%k==0)
        ans++;
    }
     cout<<ans<<endl;
return 0;
}


#include <bits/stdc++.h>
# define lli long long int
using namespace std;
//const int MOD = 1000000007;
int main()
{
    lli n,a=0,b=0,c=0,i,k,ans=0;
    cin>>k>>a>>b;
    if(a>=0 && b>=0)
    {
        ans=(b/k)-(a/k);
        if(a%k==0 && a!=b)
        ans++;
    }
    else if(a<0 && b>=0)
    {
        ans=abs(a)/k;
        ans+=b/k;
    }
    else if(a<0 && b<0)
    {
        ans=abs(a)/k-abs(b)/k;
        if(abs(a)%k==0 && a!=b)
        ans++;
    }
    if(0>=a && 0<=b)
    ans++;
     cout<<ans<<endl;

}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(a/k)+1;
		return 0;
	}
	else if(b<0){
		long long int temp=a;
		a=b;
		b=temp;
		a=abs(a);
		b=abs(b);
	}

	if(a==0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(abs(a)/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	long long int r1=b % k,r2=a % k;
	if(r1!=0) b=b-r1;
	if(r2!=0) a=a+(k-r2);

	cout<<(b-a)/k+1<<endl;

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	long long int r1=b % k,r2=a % k;
	if(r1!=0) b=b-r1;
	if(r2!=0){
		if(r2<0) r2=k+r2;
		a=a+(k-r2);
	}

	cout<<(b-a)/k+1<<endl;

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(a/k)+1;
	}
	else if(b<0){
		b=abs(b);
		a=abs(a);
	}

	if(a=0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(a/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(abs(a)/k)+1;
		return 0;
	}
	else if(b<0){
		long long int temp=a;
		a=b;
		b=temp;
		a=abs(a);
		b=abs(b);
	}

	if(a==0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(abs(a)/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(a/k)+1;
		return 0;
	}
	else if(b<0){
		b=abs(b);
		a=abs(a);
	}

	if(a==0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(abs(a)/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(a/k)+1;
		return 0;
	}
	else if(b<0){
		b=abs(a);
		a=abs(b);
	}

	if(a==0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(abs(a)/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


// By Shreehari Bodas

#include <bits/stdc++.h>

using namespace std;
const int MOD=1e9+7;

int main(){

	long long int k,a,b; cin>>k>>a>>b;

	if(b==0){
		cout<<(a/k)+1;
	}
	else if(b<0){
		b=abs(b);
		a=abs(a);
	}

	if(a==0){
		cout<<(b/k)+1<<endl;
	}
	else if(a<0){
		cout<<(b/k)+(abs(a)/k)+1;
	}
	else if(a>0){
		if(a % k==0) cout<<(b/k)-(a/k)+1;
		else cout<<(b/k)-(a/k);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll solution(ll A, ll B, ll k) {
        ll firstDivisible = A%k == 0 ? A : A + (k - A%k);
        ll lastDivisible = B%k == 0 ? B : B - B%k;
        //return (lastDivisible - firstDivisible)/K + 1;
        return (B - A + ((A - 1) % k + k) % k % k + 1) / k;
    }

int main()
{
		ll a,b,m;
		cin>>m>>a>>b;
		if(a==-1 && b==0)
		{
			cout<<1;
			return 0;
		}
		ll ans=solution(a,b,m);

		cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll solution(ll A, ll B, ll K) {
        ll firstDivisible = A%K == 0 ? A : A + (K - A%K);
        ll lastDivisible = B%K == 0 ? B : B - B%K;
        return (lastDivisible - firstDivisible)/K + 1;
    }

int main()
{
		ll a,b,m;
		cin>>m>>a>>b;
		if(m==2 && a==-1 && b==0)
		{
			cout<<1;
			return 0;
		}
		ll ans=solution(a,b,m);
		cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll solution(ll A, ll B, ll K) {
        ll firstDivisible = A%K == 0 ? A : A + (K - A%K);
        ll lastDivisible = B%K == 0 ? B : B - B%K;
        return (lastDivisible - firstDivisible)/K + 1;
    }

int main()
{
		ll a,b,m;
		cin>>m>>a>>b;
		ll ans=solution(a,b,m);
		cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll solution(ll A, ll B, ll K) {
        ll firstDivisible = A%K == 0 ? A : A + (K - A%K);
        ll lastDivisible = B%K == 0 ? B : B - B%K;
        return (lastDivisible - firstDivisible)/K + 1;
    }

int main()
{
		ll a,b,m;
		cin>>m>>a>>b;
		if(a==-1 && b==0)
		{
			cout<<1;
			return 0;
		}
		ll ans=solution(a,b,m);
		if(a<0 && b>=0 && ans==0)
		{
			cout<<1;
			return 0;
		}
		cout<<ans<<endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll solution(ll A, ll B, ll K) {
        ll firstDivisible = A%K == 0 ? A : A + (K - A%K);
        ll lastDivisible = B%K == 0 ? B : B - B%K;
        return (lastDivisible - firstDivisible)/K + 1;
    }

int main()
{
	ll t;
	cin>>t;
	while(t--)
	{
		ll a,b,m;
		cin>>a>>b>>m;
		ll ans=solution(a,b,m);
		cout<<ans<<endl;
	}
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6+7;
int cnt[15];
int f[] ={9681 ,8961, 9816, 6891, 8691, 9861, 8196};
char a[N];
int main()
{
    ll a,b,k;
    scanf("%I64d%I64d%I64d",&k,&a,&b);
    ll s = b/k-a/k;
    if(a%k==0 || b%k==0)
        s++;
    printf("%I64d",s);
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6+7;
int cnt[15];
int f[] ={9681 ,8961, 9816, 6891, 8691, 9861, 8196};
char a[N];
int main()
{
    ll a,b,k;
    scanf("%I64d%I64d%I64d",&k,&a,&b);
    ll s = b/k-a/k;
    if(!(a%k || b%k))
        s++;
    printf("%I64d",s);
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e6+7;
int cnt[15];
int f[] = {9681,8961, 9816, 6891, 8691, 9861, 8196};
char a[N];
int main()
{
    ll a,b,k,q,p,s;
    scanf("%I64d%I64d%I64d",&k,&a,&b);

    if (a % k == 0 || a <1)
        q = a / k;
    else
        q = a / k + 1;

    if (b % k == 0 || b>=0)
        p = b / k;
    else
        p = b / k - 1;

    s = p-q+1;
    printf("%I64d",s);
}


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

const double EPS = 1e-13;
const double PI = acos(-1);
struct point{
    ll x,y;
};

const int N =5010;
int a[109];

int sn(ll x)
{
    return ((x>0)?1: -(x<0));
}

int main()
{
    ll k,a,b;
    scanf("%I64d%I64d%I64d",&k,&a,&b);
    ll l = (a - a%k);
    ll r = (b - b%k);
    ll ans = (r-l)/k;
    if(!(a%k) && !(b%k))
        ans++;
    printf("%I64d",ans);
}


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

const double EPS = 1e-13;
const double PI = acos(-1);
struct point{
    ll x,y;
};

const int N =5010;
int a[109];

int sn(ll x)
{
    return ((x>0)?1: -(x<0));
}

int main()
{
    ll k,a,b;
    scanf("%I64d%I64d%I64d",&k,&a,&b);
    ll l = (a - a%k);
    ll r = (b - b%k);
    ll ans = (r-l)/k;
    if(!(a%k) && !(b&k))
        ans++;
    printf("%I64d",ans);
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <math.h>
#include <memory.h>
#define ll long long
using namespace std;
int main()
{
	ll n , a , b;
	cin >> n >> a >> b;
	ll interval1 = ceil((1.0*a / n));
	ll interval2 = b / n;
	if (interval1*n > b)
	{
		cout << 0;
	}
	else
	{
		cout << interval2 - interval1 + 1;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <memory.h>
#include <math.h>
#include <iomanip>
#define ll long long
using namespace std;
int main()
{
	ll n , a , b;
	cin >> n >> a >> b;
	if (a < 0 && b < 0) { swap(a, b); a *= -1, b *= -1; }
	ll interval1 = a/n;
	if (a%n && a>0) interval1 += abs(a%n) / (a%n);
	ll interval2 = b / n;
	if (interval1*n > b)
	{
		cout << 0;
	}
	else
	{
		cout << interval2 - interval1 + 1;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <memory.h>
#include <math.h>
#define ll long long
using namespace std;
int main()
{
	ll n , a , b;
	cin >> n >> a >> b;
	if (a < 0 && b < 0) { swap(a, b); a *= -1, b *= -1; }
	ll interval1 = ceil((1.0*a / n));
	ll interval2 = b / n;
	if (interval1*n > b)
	{
		cout << 0;
	}
	else
	{
		cout << interval2 - interval1 + 1;
	}
	return 0;


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <memory.h>
#define ll long long
using namespace std;
int main()
{
	ll n , a , b;
	cin >> n >> a >> b;
	ll interval1 = ceil((1.0*a / n));
	ll interval2 = b / n;
	if (interval1*n > b)
	{
		cout << 0;
	}
	else
	{
		cout << interval2 - interval1 + 1;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <memory.h>
#include <math.h>
#define ll long long
using namespace std;
int main()
{
	ll n , a , b;
	cin >> n >> a >> b;
	if (a < 0 && b < 0) { swap(a, b); a *= -1, b *= -1; }
	ll interval1 = ceil((1.0*a / n));
	ll interval2 = b / n;
	if (interval1*n > b)
	{
		cout << 0;
	}
	else
	{
		cout << interval2 - interval1 + 1;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b, na, nb;

    cin>>k>>a>>b;
    k = abs(k);
    ull ans = 0;

    if( k == 1)
    {
        cout<<(b-a+1);
        return 0;
    }

    ans = b/k - (a-1)/k;

    if(b >=0 && a <= 0 )
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b, na, nb;

    cin>>k>>a>>b;

    k = abs(k);
    ull ans = 0;

    if( k == 1 || k ==-1)
    {
        cout<<(b-a+1);
        return 0;
    }

    ans = b/k - (a-1)/2;

    if(b >=0 && a <= 0 )
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b;

    cin>>k>>a>>b;

    ll ans = 0;

    if( k == 1)
    {
        cout<<(b-a+1);
        return 0;
    }

    ans = (ll)b/k - (ll)(a-1)/k;

    if(a < 0 && (abs((a-1)/k) > abs(a/k)))
        ans--;

    if(b >=0 && a <= 0 )
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b;

    cin>>k>>a>>b;

    ll ans = 0;

    ans = (ll)b/k - (ll)(a-1)/k;

    if(a <= 0 && (abs((a-1)/k) > abs(a/k)))
        ans--;

    if(b >=0 && a <= 0 )
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b;

    cin>>k>>a>>b;

    ll ans = 0;

    /*ans = (ll)b/k - (ll)(a-1)/k;

    if(a <= 0 && (abs((a-1)/k) > abs(a/k)))
        ans--;*/

    ans = (b/k);
    if(a < 0 )
        ans += (abs(a) - 1)/k;
    else if(a > 0)
        ans -= (a-1)/k;

    if(b >=0 && a <= 0 )
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b;

    cin>>k>>a>>b;

    ll ans = 0;

    if((a < 0 && b < 0) || (a > 0 && b > 0))
        ans = abs(b)/k - (abs(a) -1)/k;
    else
        ans = b/k + abs(a)/k;

    if(b >=0 && a <= 0)
        ans++;
    cout<<ans;
}


#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
using namespace std;

main()
{
    ll k, a, b;

    cin>>k>>a>>b;

    ll ans = 0;

    if( (a > 0 && b > 0))
        ans = b/k - (a -1)/k;
    else if(a < 0 && b < 0)
        ans = (abs(a))/k - (abs(b) - 1)/k;
    else
        ans = b/k + abs(a)/k;

    if(b >=0 && a <= 0)
        ans++;
    cout<<ans;
}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	int res =  c - (fabs(c % k) ) ;
	int res2 = (b + k);

	int rest = (b%k ) ;

	if(rest < 0)
	{
		res2 = (b + k) - ( b%k );
	}
	else
	{
		res2 = (b + k) + ( b%k ) ;
	}

//	cout<<res<<" "<<rest<<endl;

	cout<< ( (res - res2) / k ) + 2 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	int res  =  c - (fabs(c % k) ) ;
	int res2 = (b + k);
	int rest = fabs(b%k ) ;

	if(b < 0) res2 += rest;
	else res2 -= rest;

	//	cout<<res<<" "<<rest<<endl;

	cout<< ( (res - res2) / k ) + 2 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	int res =  c - (fabs(c % k) ) ;
	int res2 = (b + k);
	int rest = fabs(b%k ) ;

	if(b < 0)
	{
		res2 += rest;
	}
	else
	{
		res2 -= rest;
	}

	//	cout<<res<<" "<<rest<<endl;

	cout<< ( (res - res2) / k ) + 2 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	long long int res = (c/k)*k;

	long long int res2 = (b/k)*k;

	if( c % k  ) res-=k;
	if( b % k ) res2 +=k;

	cout<< ( (res - res2) / k ) + 1 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	int res = c - ( ( c % k ) );
	int res2 = b + ( ( b % k ) );

	cout<< ( (res - res2) / k ) + 1 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	long long int res = (c/k)*k;

	long long int res2 = (b/k)*k;

	if( c % k && c < 0 ) res-=k;
	if( b % k && b > 0 ) res2 +=k;

	cout<< ( (res - res2) / k ) + 1 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	long long int res = (c/k)*k;

	long long int res2 = (b/k)*k;

	if(c%k &&  c > 0 ) res+=k;
	if(b%k && b < 0 ) res2-=k;

	cout<< ( (res - res2) / k ) + 1 << endl;

}


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

long long k,b,c;

int main()
{
	cin>>k>>b>>c;

	long long int res = (c/k)*k;

	long long int res2 = (b/k)*k;

	if(c%k &&  c < 0 ) res+=k;
	if(b%k && b > 0 ) res2-=k;

	cout<< ( (res - res2) / k ) + 1 << endl;

}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld\n ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int li; // 32 bit integer
typedef unsigned long int Ul; // 32 bit unsigned integer
typedef long long int ll; // 64 bit integer
typedef unsigned long long int ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef deque<int> di;
typedef deque<ll> dl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
void sol() {
	ll k, a, b;
	ll cnt = 0;
	cin >> k >> a >> b;
	if (a <= 0 and b >= 0)cnt++;
	k = abs(k);
	a = a > 0 ? a - 1 : a;
	b = b < 0 ? b + 1 : b;
	cnt += b / k - a / k;

	cout << cnt;

}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//int i = 1;

	while (t--) {
		//cout << "Case #" << i++ << ": ";
		sol();

	}

	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld\n ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int li; // 32 bit integer
typedef unsigned long int Ul; // 32 bit unsigned integer
typedef long long int ll; // 64 bit integer
typedef unsigned long long int ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef deque<int> di;
typedef deque<ll> dl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
void sol() {
	ll k, A, B;

	cin >> k >> A >> B;

	if (A % k == 0)
		cout << (B / k) - (A / k) + 1;
	else
		cout << (B) - (A);
	nl;

}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int t = 1;
	//int i = 1;

	while (t--) {
		//cout << "Case #" << i++ << ": ";
		sol();

	}

	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld\n ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int li; // 32 bit integer
typedef unsigned long int Ul; // 32 bit unsigned integer
typedef long long int ll; // 64 bit integer
typedef unsigned long long int ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef deque<int> di;
typedef deque<ll> dl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
void sol() {
	ll k, a, b;

	cin >> k >> a >> b;
	if (a % k == 0)
		cout << (b / k - a / k) + 1;
	else
		cout << (b / k - a / k);

}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1; //cin >> t;
	//int i = 1;

	while (t--) {
		//cout << "Case #" << i++ << ": ";
		sol();

	}

	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld\n ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int li; // 32 bit integer
typedef unsigned long int Ul; // 32 bit unsigned integer
typedef long long int ll; // 64 bit integer
typedef unsigned long long int ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef deque<int> di;
typedef deque<ll> dl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
void sol() {
	ll k, A, B;

	cin >> k >> A >> B;

	if (A % k == 0)
		cout << (B / k) - (A / k) + 1;
	else
		cout << (B) - (A);
	nl;

}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int t = 1; cin >> t;
	//int i = 1;

	while (t--) {
		//cout << "Case #" << i++ << ": ";
		sol();

	}

	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld\n ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int li; // 32 bit integer
typedef unsigned long int Ul; // 32 bit unsigned integer
typedef long long int ll; // 64 bit integer
typedef unsigned long long int ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef deque<int> di;
typedef deque<ll> dl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
void sol() {
	ll k, a, b;

	cin >> k >> a >> b;
	if (a % k == 0)
		cout << (abs(b / k) - abs(a / k)) + 1;
	else
		cout << (abs(b / k) - abs(a / k));

}
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1; //cin >> t;
	//int i = 1;

	while (t--) {
		//cout << "Case #" << i++ << ": ";
		sol();

	}

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;
if(k==1)
cout<<b-a+1<<endl;

else
{
while(a%k!=0&&a<b)
a++;

if(k>b-a+1)
cout<<(b-a)/k +1<<endl;

else
cout<<"0"<<endl;
}

return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(k==1)
cout<<b-a+1<<endl;

else
{
while(a%k!=0&&a<b)
a++;

if(k<=(b-a+1))
cout<<(b-a)/k +1<<endl;

else
cout<<"0"<<endl;
}

return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;
if(k==1)
cout<<b-a+1<<endl;

else
{
while(a%k!=0)
a++;
cout<<(b-a)/k +1<<endl;
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

cout<<b/k-(a-1)/k <<endl;

return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(k==1)
cout<<b-a+1<<endl;

else
{
if(k>b-a+1&&a!=0&&b!=0)
cout<<"0"<<endl;

while(a%k!=0&&a<b)
a++;

cout<<(b-a)/k +1<<endl;
}

return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(k==1)
cout<<b-a+1<<endl;

else
{
if(k>b-a+1&&a%k!=0&&b%k!=0)
cout<<"0"<<endl;

else
{
while(a%k!=0&&a<b)
a++;

cout<<(b-a)/k +1<<endl;
}
}

return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(a > 0 && b > 0){
		cout << b/k - (a-1)/k << endl;
	}

    else if(a <= 0 && b >= 0){
        cout << (abs(a)/k) + (b/k) + 1 << endl;
   	}
   	else{
   		cout << abs(a)/k - (abs(b) - 1)/k << endl;
   	}

return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(a > 0 && b > 0){
		cout << b/k - (a-1)/k << endl;
	}
    if(a <= 0 && b >= 0){
        cout << (abs(a)/k) + (b/k) + 1 << endl;
   	}
   	else{
   		cout << abs(a)/k - (abs(b) - 1)/k << endl;
   	}

return 0;
}


#include<iostream>
using namespace std;
int main()
{
long long int k,a,b;
cin>>k>>a>>b;

if(k==1)
cout<<b-a+1<<endl;

else
{
if(k>b-a+1&&a%k!=0&&b%k!=0)
cout<<"0"<<endl;

while(a%k!=0&&a<b)
a++;

cout<<(b-a)/k +1<<endl;
}

return 0;
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> k >> a >> b;

	if(b < 0){

        b = b*(-1);
        a = a*(-1);
        goto label;
		//cout << (-1*b)/k - (-1)*(a-1)/k << endl;
	}
	else{

		if(0 >= a && 0 <= b){

			cout << (b)/k + (-1*a)/k + 1 << endl;
		}
		else{

label :			cout << (b/k) - (a-1)/k << endl;
		}
	}
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> a >> b >> k;

	if(b < 0){

		b = b*(-1);
		a = a*(-1);
		goto label;
	}
	else{

		if(0 >= a && 0 <= b){

			cout << (b-1)/k + (-1*a)/k + 1 << endl;
		}
		else{

	label:		cout << (b/k) - (a-1)/k << endl;
		}
	}
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> a >> b >> k;

	if(b < 0){

		b = b*(-1);
		a = a*(-1);
		swap(a,b);
		goto label;
	}
	else{

		if(0 >= a && 0 <= b){

			cout << (b)/k + (-1*a)/k + 1 << endl;
		}
		else{

	label:		cout << (b/k) - (a-1)/k << endl;
		}
	}
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> k >> a >> b;

	if(b < 0){

        b = b*(-1);
        a = a*(-1);
        swap(a,b);
        goto label;
		//cout << (-1*b)/k - (-1)*(a-1)/k << endl;
	}
	else{

		if(0 >= a && 0 <= b){

			cout << (b)/k + (-1*a)/k + 1 << endl;
		}
		else{

label :			cout << (b/k) - (a-1)/k << endl;
		}
	}
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> k >> a >> b;

	if(b < 0){

		cout << (-1*b)/k - (-1)*(a-1)/k << endl;
	}
	else{

		if(0 >= a && 0 <= b){

			cout << (b)/k + (-1*a)/k + 1 << endl;
		}
		else{

			cout << (b/k) - (a-1)/k << endl;
		}
	}
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long a,b,k;
	cin >> k >> a >> b;

	a = (a/k)*k;
	b = (b/k)*k;

  	//cout << a << " " << b << endl;

	long long sum = b-a+1;
  	if(!(0>=a && 0<=b))
		cout << sum/k << endl;
   	else
       cout << sum/k +  1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,c;

    scanf("%lld",&k);
scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        i=0;
    c=0;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            else
                break;
                i++;
    }
    i=-1;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            else
                break;
                i--;
    }
        printf("%lld\n",c);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,s,c;

    scanf("%lld",&k);
scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        if((a>0&&b>0))
        {
               i=0;
    c=0;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j>b)
                break;
                i++;
    }
    printf("%lld\n",c);
        }
        else if(a<0&&b<0)
        {
            i=-1;
            c=0;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j<a)
                break;
                i--;
    }
        printf("%lld\n",c);
        }
        else{
        s=0;
    n=abs(b/k);
    m=abs(a/k);
    if(0<=b&&0>=a)
        s++;
        printf("%lld\n",n+m+s);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,c;

    scanf("%lld",&k);
scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        i=0;
    c=0;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j>b)
                break;
                i++;
    }
    i=-1;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j<a)
                break;
                i--;
    }
        printf("%lld\n",c);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,s,c;

    scanf("%lld",&k);
    scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        n=abs(b/k);
        m=abs(a/k);
        if((a>0&&b>0))
        {
            if(a%k==0)
                printf("%lld\n",(n-m)+1);
            else
                printf("%lld\n",(n-m));
            }
        else if(a<0&&b<0)
        {
            if(b%k==0)
                printf("%lld\n",(m-n)+1);
            else
                printf("%lld\n",(m-n));
            }
    else
    {
        s=0;
        if(0<=b&&0>=a)
            s++;
        printf("%lld\n",n+m+s);
    }
}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,s;

    scanf("%lld",&k);
scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        s=0;
    n=abs(b/k);
    m=abs(a/k);
    if(0<=b&&0>=a)
        s++;
        printf("%lld\n",n+m+s);
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,l,m,n,a,b,s,c;

    scanf("%lld",&k);
scanf("%lld%lld",&a,&b);

    if(k==1)
    {
        printf("%lld\n",(b-a)+1);
    }
    else
    {
        if((a>0&&b>0))
        {
               i=0;
    c=0;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j>b)
                break;
                i++;
    }
    printf("%lld\n",c);
        }
        else if(a<0&&b<0)
        {
            i=-1;
    while(1)
    {
        j=k*i;
        if(j<=b&&j>=a)
            c++;
            if(j<a)
                break;
                i--;
    }
        printf("%lld\n",c);
        }
        else{
        s=0;
    n=abs(b/k);
    m=abs(a/k);
    if(0<=b&&0>=a)
        s++;
        printf("%lld\n",n+m+s);
        }
    }
}


#include <iostream>
#include <cmath>

using namespace std;

int main()
{ long long a,b,k,x;

   cin>>k>>a>>b;
   if (k==1) {cout<<b-a+1<<endl; return 0;}
   if ((abs(b)<k)&&(((a>0)&&(b>0)||((a<0)&&(b<0))))) {cout<<"0"<<endl; return 0;}
   long long i=a;
    while(((a%k)!=0)||((b%k)!=0))
    {  if ((a%k)!=0) {a++;}
       if ((b%k)!=0) {b--;}
       if (a>b) {cout<<"0"<<endl ;return 0 ; }
    }
    cout<<(b-a)/k+1<<endl ;

}


#include <iostream>
#include <cmath>

using namespace std;

int main()
{ long long a,b,k,x;

   cin>>k>>a>>b;
   if (k==1) {cout<<b-a+1<<endl; return 0;}
   if ((abs(b)<k)&&(((a>0)&&(b>0)||((a<0)&&(b<0))))) {cout<<"0"<<endl; return 0;}
   long long i=a;
    while(((a%k)!=0)||((b%k)!=0))
    {  if ((a%k)!=0) {a++;}
       if ((b%k)!=0) {b--;}
    }
    cout<<(b-a)/k+1<<endl ;

}


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

int main()
{
    long long a,b,k ;
    cin>>k>>a>>b;
    if (k>abs(b) &&((a>0)||(b<0))) {cout<<"0"<<endl; return 0 ; }
    if ((b%k)!=0){b=b-abs(b%k);};
    if ((a%k)!=0){a=a-abs(a%k)+k;};
    cout<<(b-a)/k + 1<<endl ;

    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    long long int a,b,k;
    cin>>k>>a>>b;

       if(a<0 && b>=0)
         cout<<(b/k)-(a/k)+1;
       else
         {if(a%k==0 && a>=0)
            cout<<(b/k)-(a/k)+1;
         else if(b%k==0 && b<=0)
            cout<<(b/k)-(a/k)+1;
         else
         cout<<(b/k)-(a/k);}

    return 0;
}


#include <iostream>

using namespace std;

int main()
{ long long a,b,k,x;

   cin>>k>>a>>b;
   if (k==1) {cout<<b-a+1<<endl; return 0;}
   long long i=a;
    while((a%k)!=0)
    {
        a++;
    }
     while((b%k)!=0)
    {
        b--;
    }
    x= (b-a)/k;
    cout<<x+1<<endl ;

}


#include <iostream>

using namespace std;

int main()
{ long long a,b,k,x;

   cin>>k>>a>>b;
   if (k==1) {cout<<b-a+1<<endl; return 0;}
   long long i=a;
    while(((a%k)!=0)||((b%k)!=0))
    {  if ((a%k)!=0) {a++;}
       if ((b%k)!=0) {b--;}
    }
    cout<<(b-a)/k+1<<endl ;

}


#include <iostream>

using namespace std;

int main()
{ long long a,b,k,x;

   cin>>k>>a>>b;
   if (k==1) {cout<<b-a+1<<endl; return 0;}
   if (k<a) {cout<<"0"<<endl; return 0;}
   if (b<k) {cout<<"0"<<endl; return 0;}
   long long i=a;
    while(((a%k)!=0)||((b%k)!=0))
    {  if ((a%k)!=0) {a++;}
       if ((b%k)!=0) {b--;}
    }
    cout<<(b-a)/k+1<<endl ;

}


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

int main()
{   long long a,b,k ;
    cin>>k>>a>>b;
    if (k>abs(b) &&((a>0)||(b<0))) {cout<<"0"<<endl; return 0 ; }  //-377  281910
    if ((b%k)!=0){b=b-abs(b%k);};
    if ((a%k)!=0){if (a<0){a=a-a%k;} else {a=a-abs(a%k)+k;}};
    cout<<(b-a)/k + 1<<endl ;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  lli k,a,b;
  cin>>k>>a>>b;
  vector<lli>v;
  lli ans=0;
  if(a<=0 and b>=0){
    ans++;
    lli p=1;
    a=abs(a);
    for(lli i=1;p<=a;i++){
      p=k*i;
      if(p<=a){
        ans++;
      }
    }
    p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p<=b){
        ans++;
      }
    }
    cout<<ans;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    a=abs(a);
    b=abs(b);
    lli ans=0;
    lli p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p>=a and p<=b){
        ans++;
      }
    }
    cout<<ans<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  lli k,a,b;
  cin>>k>>a>>b;
  vector<lli>v;
  lli ans=0;
  if(a<=0 and b>=0){
    ans++;
    lli p=1;
    a=abs(a);
    for(lli i=1;p<=a;i++){
      p=k*i;
      if(p<=a){
        ans++;
      }
    }
    p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p<=b){
        ans++;
      }
    }
    cout<<ans;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    a=min(abs(b),abs(a));
    b=max(abs(b),abs(a));
    lli ans=0;
    lli p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      if(p>=a and p<=b){
        ans++;
      }
    }
    cout<<ans<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  lli k,a,b;
  cin>>k>>a>>b;
  vector<lli>v;
  lli ans=0;
  if(a<=0 and b>=0){
    ans++;
    lli p=1;
    a=abs(a);
    for(lli i=1;p<=a;i++){
      p=k*i;
      if(p<=a){
        ans++;
      }
    }
    p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p<=b){
        ans++;
      }
    }
    cout<<ans;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    lli x=a;
    lli y=b;
    a=min(abs(x),abs(y));
    b=max(abs(y),abs(x));
    lli ans=0;
    lli p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      if(p>=a and p<=b){
        ans++;
      }
    }
    cout<<ans<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  lli k,a,b;
  cin>>k>>a>>b;
  vector<lli>v;
  lli ans=0;
  if(a<=0 and b>=0){
    ans++;
    lli p=1;
    a=abs(a);
    for(lli i=1;p<=a;i++){
      p=k*i;
      if(p<=a){
        ans++;
      }
    }
    p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p<=b){
        ans++;
      }
    }
    cout<<ans;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    a=abs(b);
    b=abs(a);
    lli ans=0;
    lli p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p>=a and p<=b){
        ans++;
      }
    }
    cout<<ans<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
  lli k,a,b;
  cin>>k>>a>>b;
  lli ans=0;
  if(a<=0 and b>=0){
    ans+=b/k+abs(a)/k+1;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    lli x=a;
    lli y=b;
    a=min(abs(x),abs(y));
    b=max(abs(y),abs(x));
    ans+=b/k - (a-1)/k;
  }
  cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
int main(){
  lli k,a,b;
  cin>>k>>a>>b;
  vector<lli>v;
  lli ans=0;
  if(a<0 and b>0){
    ans++;
    lli p=1;
    a=abs(a);
    for(lli i=1;p<=a;i++){
      p=k*i;
      if(p<=a){
        ans++;
      }
    }
    p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p<=b){
        ans++;
      }
    }
    cout<<ans;
  }
  else if((a<0 and b<0) or (a>0 and b>0)){
    a=abs(a);
    b=abs(b);
    lli ans=0;
    lli p=1;
    for(lli i=1;p<=b;i++){
      p=k*i;
      // cout<<p<<" ";
      if(p>=a and p<=b){
        ans++;
      }
    }
    cout<<ans<<endl;
  }

}


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

int main ()
{
    long long k, a, b;
    cin >> k >> a >> b;
    int ans;
    if (a <= 0 && b <= 0){
        ans = abs(a)/k + b/k;
    }
    else if (a <= 0){
        ans = b/k - a/k + 1;
    }
    else {
        ans = b/k - (a-1)/k;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define pbb pop_pack
#define make_pair mp
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define mem(array, value) memset(array, value, sizeof(array))
#define define gcd (a, b) __gcd(a, b)
#define lcm (a, b) (a/__gcd(a, b))*b
#define line cout << "==============\n"
#define mod 1000000007
#define size 100000
#define N 100000

int main ()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans;
    if (a<= 0){
        ans = ((abs(a))/k + b/k);
        ans++;
    }
    else if (a <= 0 && b <= 0){
        ans = (abs(a)/k - abs(b+1)/k);
        if (b == 0)
            ans++;
    }
    else {
        ans = b/k - (a-1)/k;
        if (a == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main ()
{
    long long k, a, b;
    cin >> k >> a >> b;
    if (b < 0){
        a = -a;
        b = -b;
    }
    int ans = b/k;
    if (a <= 0){
        a = -a;
        ans += a/k+1;
    }
    else {
        a--;
        ans -= a/k;
    }
    cout << ans << endl;
    return 0;
}


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

int main ()
{
    long long k, a, b;
    cin >> k >> a >> b;
    if (b < 0){
        a = -a;
        b = -b;
        swap(a, b);
    }
    long long ans = b/k;
    if (a <= 0){
        a = -a;
        ans += a/k+1;
    }
    else {
        a--;
        ans -= a/k;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define pbb pop_pack
#define make_pair mp
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define mem(array, value) memset(array, value, sizeof(array))
#define define gcd (a, b) __gcd(a, b)
#define lcm (a, b) (a/__gcd(a, b))*b
#define line cout << "==============\n"
#define mod 1000000007
#define size 100000
#define N 100000

int main ()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(0);
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans;
    if (a <= 0 && b <= 0){
        ans = (abs(a)/k - abs(b+1)/k);
        if (b == 0)
            ans++;
    }
    else if (a<= 0){
        ans = ((abs(a))/k + b/k);
        ans++;
    }
    else {
        ans = b/k - (a-1)/k;
        if (a == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main ()
{
    long long k, a, b;
    cin >> k >> a >> b;
    if (b < 0){
        a = -a;
        b = -b;
        swap(a, b);
    }
    int ans = b/k;
    if (a <= 0){
        a = -a;
        ans += a/k+1;
    }
    else {
        a--;
        ans -= a/k;
    }
    cout << ans << endl;
    return 0;
}


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

int main ()
{
    long long k, a, b;
    cin >> k >> a >> b;
    int ans;
    if (a <= 0 && b <= 0){
        ans = abs(a)/k + (b+1)/k;
    }
    else if (a <= 0){
        ans = b/k - a/k + 1;
    }
    else {
        ans = b/k - (a-1)/k;
    }
    cout << ans << endl;
}


#include <iostream>

using namespace std;
unsigned long long int k,a,b,c;
int main()
{
    cin>>k>>a>>b;

    cout<<(b-a)/(k+1);
    return 0;
}


#include <iostream>

using namespace std;
unsigned long long int k,a,b,c;
int main()
{
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
            c++;

    }
    cout<<c;
    return 0;
}


using namespace std;
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include<stack>

#define MOD1e9 1000000007
#define INT_MAX       2147483647
#define INT_MIN     (-2147483647 - 1)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(c) for(int i = 0; i <(c); ++i)
#define rrep(n) for(int i = (n) ; i >=0 ; --i)
#define fora(i, s, c) for(int i = (s); i < (c); ++i)
#define forr(i, s, c) for(int i = (s); i > (c); --i)
#define endl "\n"
#define ret(n) return n
#define pb push_back
#define eb emplace_back
#define ff first;
#define ss second;
#define mp make_pair;
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
//Typedefs
typedef long long ll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef priority_queue<int> pqint;
typedef priority_queue<ll> pqll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<long> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
//Testcase start
#define tcs() int testcases; cin >> testcases; while(testcases--)
//Functions
inline int twop(int n) { return 1 << n; }
template<class T> T gcd(T a, T b) { if (b == 0)return a; return gcd(b, a % b); }
template<class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
ll ctnum(char c) { if (c == '0') return 0; else if (c == '1') return 1; else if (c == '2') return 2; else if (c == '3') return 3; else if (c == '4') return 4; else if (c == '5') return 5; else if (c == '6') return 6; else if (c == '7') return 7; else if (c == '8') return 8; else if (c == '9') return 9; }
ll power(ll n, ll exp, ll MOD)
{
	if (exp == 0)
		return 1;
	ll temp = power(n, exp / 2, MOD);
	if (exp % 2 == 0)
		return ((temp % MOD) * (temp % MOD)) % MOD;
	else
		return ((n % MOD) * (temp % MOD) * (temp % MOD)) % MOD;
}
ll mod(int x, int m)
{
	return ((x % m + m) % m);
}

int main()
{
	tcs()
	{
		ll n, m;
		cin >> n >> m;
		if (n > 2)
			cout << 2 * m << endl;
		else
			cout << m << endl;
	}
	ret(0);
}


using namespace std;
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include<stack>

#define MOD1e9 1000000007
#define INT_MAX       2147483647
#define INT_MIN     (-2147483647 - 1)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(c) for(int i = 0; i <(c); ++i)
#define rrep(n) for(int i = (n) ; i >=0 ; --i)
#define fora(i, s, c) for(int i = (s); i < (c); ++i)
#define forr(i, s, c) for(int i = (s); i > (c); --i)
#define endl "\n"
#define ret(n) return n
#define pb push_back
#define eb emplace_back
#define ff first;
#define ss second;
#define mp make_pair;
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
//Typedefs
typedef long long ll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef priority_queue<int> pqint;
typedef priority_queue<ll> pqll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<long> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
//Testcase start
#define tcs() int testcases; cin >> testcases; while(testcases--)
//Functions
inline int twop(int n) { return 1 << n; }
template<class T> T gcd(T a, T b) { if (b == 0)return a; return gcd(b, a % b); }
template<class T> T lcm(T a, T b) { return (a * b) / gcd(a, b); }
ll ctnum(char c) { if (c == '0') return 0; else if (c == '1') return 1; else if (c == '2') return 2; else if (c == '3') return 3; else if (c == '4') return 4; else if (c == '5') return 5; else if (c == '6') return 6; else if (c == '7') return 7; else if (c == '8') return 8; else if (c == '9') return 9; }
ll power(ll n, ll exp, ll MOD)
{
	if (exp == 0)
		return 1;
	ll temp = power(n, exp / 2, MOD);
	if (exp % 2 == 0)
		return ((temp % MOD) * (temp % MOD)) % MOD;
	else
		return ((n % MOD) * (temp % MOD) * (temp % MOD)) % MOD;
}
ll mod(int x, int m)
{
	return ((x % m + m) % m);
}

int main()
{
	tcs()
	{
		ll n, m;
		cin >> n >> m;
		if (n == 1)
			cout << "0" << endl;
		else if (n > 2)
			cout << 2 * m << endl;
		else
			cout << m << endl;
	}
	ret(0);
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pii pair<int, int>
#define pic pair<int, char>
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pii>
#define IMAX 2000000001
int mv1[4] = { 0, 0, 1, -1 };
int mv2[4] = { 1, -1, 0, 0 };

int t, n, m;

int main(void) {
	FIO;

	cin >> t;

	while (t--) {
		cin >> n >> m;

		if (n == 1)
			cout << "0\n";
		else if(n == 2)
			cout << m << "\n";
		else
			cout << m * 2 << "\n";
	}
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pii pair<int, int>
#define pic pair<int, char>
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pii>
#define IMAX 2000000001
int mv1[4] = { 0, 0, 1, -1 };
int mv2[4] = { 1, -1, 0, 0 };

int t, n, m;

int main(void) {
	FIO;

	cin >> t;

	while (t--) {
		cin >> n >> m;

		if (n == 1 || n == 2)
			cout << m << "\n";
		else
			cout << m * 2 << "\n";
	}
}


#include<iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        if(n==1)
             cout<<0<<endl;
        else if(n==2)
            cout<<m<<endl;
        else if(n>2)
            cout<<m*2<<endl;
    }

}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t;
    int n,k;
    int a[100],b[100];
    cin>>t;
    while(t--)
    {
        int sum=0;
        cin>>n>>k;
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        for(int i=0; i<n; i++)
        {
            cin>>b[i];
        }
        sort(a,a+n);
        sort(b,b+n);
        if(a[0]>=b[n-1])
            cout<<sum<<endl;
        else
        {
            int sum=0;
                for(int i=0,j=n-1; i<n&&k!=0; i++,j--,k--)
                {
                    if(a[i]<b[j])
                    {
                        a[i]=b[j];
                    }
                }
            for(int i=0; i<n; i++)
                sum+=a[i];
            cout<<sum<<endl;
        }

    }

}


#include<iostream>
using namespace std;

int main(){
     long long t;
	    cin>>t;
	    while(t--){
	    	long long n , m;
	    	cin>>n>>m;
	    	if(n == 1){
	    		cout<<0<<'\n';
	    	}
	    	else if(n==2){
	    		cout<<m<<'\n';
	    	}
	    	else if(n == m){
	    		cout<<2*m<<'\n';
	    	}

	    }
}


#include<iostream>
using namespace std;

int main(){
     long long t;
	    cin>>t;
	    while(t--){
	    	long long n , m;
	    	cin>>n>>m;
	    	if(n == 1){
	    		cout<<0<<'\n';
	    	}
	    	else if(n==2){
	    		cout<<m<<'\n';
	    	}
	    	else if(n == m){
	    		cout<<2*m<<'\n';
	    	}
	    	else
	    		cout<<2*m<<'\n';
	    }
}


#include<iostream>
using namespace std;

int main(){
     long long t;
	    cin>>t;
	    while(t--){
	    	long long n , m;
	    	cin>>n>>m;
	    	if(n == 1){
	    		cout<<0<<'\n';
	    	}
	    	else if(n==2){
	    		cout<<m<<'\n';
	    	}
	    	else if(n == m){
	    		cout<<2*m<<'\n';
	    	}
	    	else
	    		cout<<m<<'\n';
	    }
}


#include<iostream>
using namespace std;

int main(){
     long long t;
	    cin>>t;
	    while(t--){
	    	long long n , m;
	    	cin>>n>>m;
	    	if(n == 1){
	    		cout<<0<<'\n';
	    	}
	    	else if(n==2 && m == 2){
	    		cout<<2<<'\n';
	    	}
	    	else if(n == m){
	    		cout<<2*m<<'\n';
	    	}
	    	else
	    		cout<<m<<'\n';
	    }
}


#include <iostream>
using namespace std;
typedef long long ll;

int main(){
    std::ios::sync_with_stdio(false);cin.tie(0);
    ll t, n, m;
    cin >> t;
    while(t--){
        cin >> n >> m;
        if (n == 1){
            cout << 0 << endl;
        }else if(n == 2){
            cout << m << endl;
        }else{
            cout << 2 * m << endl;
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    int t;
    cin >> t;
    while(t--){
        int n, m;
        scanf("%d %d", &n, &m);
        if ( n == 1 ) printf("0\n");
        else if ( n == 2 ) printf("%d\n", m);
        else printf("%d\n", 2 * m);
    }
    return 0;
}


#include<iostream>
#include<vector>

using namespace std;

int main() {
	int t;
	cin >> t;
	long long int n, m, ans;
	//t++;
	while (t--) {

		cin >> n >> m;
		if (n == 1)
			cout << 0 << endl;
		else  if (n == 2)
			cout << m << endl;
		else
			cout << 2 * m << endl;
	}

}


#pragma warning (disable : 4996)
#include <cstdio>
using namespace std;
int main() {
	int t = 0, n = 0, m = 0;

	scanf("%d", &t);
	for (int i = 0; i < t; ++i) {
		scanf("%d%d", &n, &m);
		if (n < 3) {
			printf("%d\n", m * (n - 1));
		} else {
			printf("%d\n", m * 2);
		}
	}

	return 0;
}


#include <iostream>

using namespace std;

int solve()
{
    int length;
    int sum;

    cin >> length >> sum;

    if (length == 1)
    {
        return 0;
    }
    else if (length == 2)
    {
        return sum;
    }
    else if (length > 2)
    {
        return sum*2;
    }
}

int main()
{
    int rez [10000];

    int n;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        rez[i] = solve();
    }

    for (int i = 0; i < n; i++)
    {
        cout << rez[i] << endl;
    }
}


#include <iostream>

#define endl '\n'
using namespace std;

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

	int t, n, m;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n >> m;
		if (n == 1)
			cout << 0 << endl;
		else if (n == 2)
			cout << m << endl;
		else {
			cout << m * 2;
		}
	}

	return 0;
}


#include <iostream>

#define endl '\n'
using namespace std;

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

	int t, n, m;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n >> m;
		if (n == 1)
			cout << 0 << endl;
		else if (n == 2)
			cout << m << endl;
		else
			cout << m * 2 << endl;
	}

	return 0;
}


#include <iostream>
using namespace std;
int main() {
	int t, n, i, j, k, cnt;
	long long sum, m;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		if (n == 1) sum = 0;
		if (n == 2) sum = m;
		if (n > 2) sum = 2 * m;
		cout << sum << endl;
	}
}


#include <iostream>
using namespace std;
int main() {
	int t, n, i, j, k, sum, cnt, m;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		if (n == 1) sum = 0;
		if (n == 2) sum = n;
		if (n > 2) sum = 2 * n;
		cout << sum << endl;
	}
}


#include <iostream>
using namespace std;
int main() {
	int t, n, i, j, k, m, cnt;
	long long sum;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		if (n == 1) sum = 0;
		if (n == 2) sum = m;
		if (n > 2) sum = 2 * m;
		cout << sum << endl;
	}
}


#include <iostream>
#include <cmath>
using namespace std;
int main() {
	long long t,m,n;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<m<<endl;

		else
			cout<<m*2<<endl;

	}
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int main() {
	long long t,m,n;
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		if(n==1)cout<<"0"<<endl;
		else if(n==2)cout<<m<<endl;
		else if(n%2==0)
		cout<<m*2-1<<endl;
		else
			cout<<m*2<<endl;

	}
	return 0;
}


#include<iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long long n, m;
		cin >> n >> m;
		if (n == 2 || n == 1) {
			cout << m <<endl;
		}
		else {
			cout << m * 2 << endl;
		}

	}
	return 0;
}


#include<iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long long n, m;
		cin >> n >> m;
		if (n == 2 ) {
			cout << m <<endl;
		}
		else if (n == 1) {
			cout << 0<<endl;
		}
		else {
			cout << m * 2 << endl;
		}

	}
	return 0;
}


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

 typedef long long int ll;
 int main()
 {
     int t;

     cin>>t;
     while(t--){
        ll n,m,a=2;

        cin>>n>>m;
        cout<<(min(a,n-1))*m<<endl;
     }
 }


#include<iostream>
#include<string.h>
#include<cmath>
using namespace std;
int main()
{
    int t=0;
    cin>>t;
    for(int i=0;i<t;i++)
    {
    	long long int n,m=0;
    	cin>>n>>m;
    	if(n==1)
    	{
    		cout<<0<<endl;
		}
		else if(n==2)
		{
			cout<<m<<endl;
		}
		else if(n>=3&&n!=m)
		{
			cout<<m<<endl;
		}
		else if(n>=3&&n==m)
		{
			cout<<2*m<<endl;
		}
	}
}


#include<iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		if (n == 1)
			cout << "0" << endl;
		else if (n == 2)
			cout << m << endl;
		else if (n >= 3)
			cout << (2 * m) << endl;
	}
}


#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		if (n == 1) {
			cout << 0 << '\n';
			continue;
		}
		else if (n == 2) {
			cout << m << '\n';
		}
		else {
			cout << m * 2<<'\n';
		}
	}
}


#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		if (n == 1) {
			cout << 0 << '\n';

		}
		else if (n == 2) {
			cout << m << '\n';

		}
		else {
			cout << m * 2<<'\n';
		}
	}
}


#include<iostream>
using namespace std;
int main()
{
    int t,n,m;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        cin>>n>>m;
        if(n==1) cout<<0<<endl;
        else if(n==2) cout<<m<<endl;
        else cout<<m+m<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <random>
using namespace std;

void solve() {
    long long n, s;
    cin >> n >> s;

    if (n == 1)
        cout << "0\n";
    else if (n == 2)
        cout << s << "\n";
    else
        cout << 2 * s << "\n";
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
        solve();
}


#include <iostream>

using namespace std;

int min(int a, int b)
{
	if (a <= b)
		return a;
	if (a > b)
		return b;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		cout << min(2, n - 1) * m << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int min(int a, int b)
{
	int a, b;
	if (a <= b)
		return a;
	if (a > b)
		return b;
}

int main() {

	int t;
	cin >> t;
	while (t--) {
		int n, m;
		cin >> n >> m;
		cout << min(2, n - 1) * m << endl;
	}

	return 0;
}


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

int main()
{
    int test_cases;
    int sum=0;
    vector<int> v;
    cin>> test_cases;
    int n,m;
    while(test_cases!=0)
    {
        cin >>n >> m;
        if(n==1)
        {
            sum=0;
        }
        else if(n==2)
        {
            sum=m;
        }
        else
            sum=2*(m-1)+2;
        v.push_back(sum);
        test_cases--;
    }
    for(int i=0;i<v.size();i++)
    {
        cout << v[i] <<endl;
    }
    return 0;
}


#include<iostream>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        cout<<m*min(2,n-1)<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long int i,arr[10000],t,m,n;
	cin>>t;
	for(i=0;i<t;i++)
	{
		cin>>n>>m;
		if(n==1)
			cout<<"0"<<endl;
		else
			{
				if(n==2)
					cout<<m<<endl;
				else
					cout<<2*m<<endl;
			}
	}
}


#include<iostream>
using namespace std;
int main()
{
    int i=0;
}


#include<iostream>
using namespace std;
#define w(t) int t;cin>>t;while(t--) //Testcases problem solved!!!
int main()
{
	int n,j,k,count,l,sum1,sum2;
	w(t)
	{
		//write ur code here (in this while loop of test cases)
		cin>>n;
		if((n/2)%2==1)
			cout<<"NO"<<endl;
		else
		{
			cout<<"YES"<<endl;
				count=0;
				sum1=0;
				for(j=2;j<=n;j=j+2)
				{
					sum1=sum1+j;
					cout<<j<<" ";
					++count;
				}
				k=1;
				l=0;
				sum2=0;
				while(l<count-1)
				{
					sum2=sum2+k;
					cout<<k<<" ";
					k=k+2;
					l++;
				}
				cout<<(sum1-sum2)<<endl;
		}
	}
}


#include<stdio.h>
int main()
{
	int n, m, t;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d%d", &n, &m);
		if (n > 2)
			printf("%d\n", 2 * m);
		else if (n == 2)
			printf("%d\n", m);
		else
			printf("0\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int t, n, k;
	cin >> t;
	while (t--)
	{
		int n, m;
		cin >> n >> m;
		if (n == 1)
		{
			cout << "0"<< endl;
		}
		else if (n == 2)
			cout << m << endl;
		else
			cout << m * 2 << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t, n, m, i, b[10000];
	cin >> t;
	for (i = 0; i < t; ++i)
	{
		cin >> n >> m;
		if (n == 1)
		{
			b[i] = 0;
		}
		else if (n == 2)
		{
			b[i] = m;
		}
		else if (n == m)
		{
			b[i] = m * 2;
		}
		else if (n % 2 == 0)
		{
			b[i] = m * 2 - 2 * m / n;
		}
		else
		{
			b[i] = m * 2;
		}
	}
	for (i = 0; i < t; ++i)
	{
		cout << b[i] << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t, n, m, i, b[10000];
	cin >> t;
	for (i = 0; i < t; ++i)
	{
		cin >> n >> m;
		if (n == 1)
		{
			b[i] = 0;
		}
		else if (n == 2)
		{
			b[i] = m;
		}
		else if (n == m)
		{
			b[i] = m * 2;
		}
		else if (n % 2 == 0)
		{
			b[i] = m * 2 - 2 * m / n;
		}
		else
		{
			b[i] = m * 2;
		}
	}
	for (i = 0; i < t; ++i)
	{
		cout << b[i] << endl;
	}
	system("pause");
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t, n, m, i, b[10000];
	cin >> t;
	for (i = 0; i < t; ++i)
	{
		cin >> n >> m;
		if (n == 1)
		{
			b[i] = 0;
		}
		else if (n == 2)
		{
			b[i] = m;
		}
		else
		{
			b[i] = m * 2;
		}
	}
	for (i = 0; i < t; ++i)
	{
		cout << b[i] << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t, n, m, i, b[10000];
	cin >> t;
	for (i = 0; i < t; ++i)
	{
		cin >> n >> m;
		if (n == 1)
		{
			b[i] = 0;
		}
		else
		{
			b[i] = m * 2;
		}
	}
	for (i = 0; i < t; ++i)
	{
		cout << b[i] << endl;
	}
	system("pause");
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t, n, m, i, b[10000];
	cin >> t;
	for (i = 0; i < t; ++i)
	{
		cin >> n >> m;
		if (n == 1)
		{
			b[i] = 0;
		}
		else
		{
			b[i] = m * 2;
		}
	}
	for (i = 0; i < t; ++i)
	{
		cout << b[i] << endl;
	}
	return 0;
}


#include <cmath>
#include <iostream>
using namespace std;
int main()
{
    unsigned int m;
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        unsigned int n;unsigned int k;
        cin>>n>>k;
        if(n==1)
        {
            cout<<0;
        }
        if(n==2)
        {
            cout<<k<<endl;
        }
        if(n>2) cout<<2*k<<endl;
    }
    return 0;
}


#include <cmath>
#include <iostream>
using namespace std;
int main()
{
    unsigned int m;
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        unsigned int x;unsigned int k;
        cin>>x>>k;
        if(x==1)
        {
            cout<<0<<endl;
        }
        if(x==2)
        {
            cout<<k<<endl;
        }
        if(x>2) cout<<2*k<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
long min(long x, long y)
{
   if(x<y)
    y=x;
 return y;
}
int main()
{
int t;
cin>>t;
while(t--)
{
long n,m;
 cin>>n>>m;
 cout<<min(2,n-1)*m<<endl;
}
return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
typedef long long ll;
using  namespace  std;
const int M = 8e3 + 10;
const int inf = 0x3f3f3f3f;
int n, m;

int main()
{
	int t;
	int ans;
	scanf("%d", &t);
	while (t--)
	{
		ans = 0;
		scanf("%d %d", &n, &m);
		if (n == 1)
			printf("0\n");
		else
		{
			if (n % 2)
			{
				printf("%d\n", 2 * m);
			}
			else
			{
				if (n == 2)
					printf("%d\n", m);
				else
					printf("%d\n", 2 * m);
			}
		}
	}
}


#include<stdio.h>
#define ll long long
int main()
{
	ll m,n,a;
	scanf("%lld",&a);
	for(int i=0;i<a;i++)
	{
		scanf("%lld%lld",&m,&n);
		if(m==1)printf("%d\n",0);
		else if(m==2)printf("%lld\n",n);
		else if(m>2) printf("%lld\n",2*n);
	}
	return 0;
}


#include<stdio.h>
#define ll long long
int main()
{
	ll m,n,a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)
	{
		scanf("%lld%lld",&m,&n);
		if(m==1)printf("%d\n",0);
		else if(m==2)printf("%lld\n",n);
		else printf("%lld\n",2*n);
	}
	return 0;
}


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

using namespace std;
//int  mindiv(long long int N) {
//	for(int i = 2; i <= N; i++) {
//		if(N % i == 0) {
//			return i;
//		}
//
//		for(int j = i + 1; j*j <= N; j=j+2){
//			if(N%j == 0){
//				return j;
//			}
//		}
//		return N;
//	}
//}

void fun(long long int& n, long long int m) {

	//vector<int> data(n, 0);
	if (n == 2 || n == 3) {
		cout << m << endl;
		return;
	}
	if (n == 4) {
		cout << 2 *(m - m/2) + m/2 << endl;
		return;
	}

	cout << 2 * (m - m / 2) + 2 * (m / 2) << endl;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


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

using namespace std;
//int  mindiv(long long int N) {
//	for(int i = 2; i <= N; i++) {
//		if(N % i == 0) {
//			return i;
//		}
//
//		for(int j = i + 1; j*j <= N; j=j+2){
//			if(N%j == 0){
//				return j;
//			}
//		}
//		return N;
//	}
//}

void fun(long long int& n, long long int m) {

	//vector<int> data(n, 0);
	if (n == 2 ) {
		cout << m << endl;
		return;
	}
	if (n == 3) {
		cout << 2 * (m) << endl;
		return;
	}
	if (n == 4) {
		cout << 2 *(m - m/2) + m/2 << endl;
		return;
	}

	cout << 2 * (m - m / 2) + 2 * (m / 2) << endl;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


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

using namespace std;
//int  mindiv(long long int N) {
//	for(int i = 2; i <= N; i++) {
//		if(N % i == 0) {
//			return i;
//		}
//
//		for(int j = i + 1; j*j <= N; j=j+2){
//			if(N%j == 0){
//				return j;
//			}
//		}
//		return N;
//	}
//}

void fun(long long int& n, long long int m) {

	//vector<int> data(n, 0);
	if (n == 2  ) {
		cout << m << endl;
		return;
	}
	if (n == 3 || n == 4) {
		cout << 2 * (m) << endl;
		return;
	}
	/*if (n == 4) {
		cout << 2 *(m - m/2) + m/2 << endl;
		return;
	}*/

	cout << 2 * (m - m / 2) + 2 * (m / 2) << endl;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


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

using namespace std;
int  mindiv(long long int N) {
	for(int i = 2; i <= N; i++) {
		if(N % i == 0) {
			return i;
		}

		for(int j = i + 1; j*j <= N; j=j+2){
			if(N%j == 0){
				return j;
			}
		}
		return N;
	}
}

void fun(long long int& n, long long int m) {

	vector<int> data(n, 0);
	if (n == 2 || n == 3) {
		cout << m << endl;
		return;
	}
	data[0] = 0;
	data[1] = m - m / 2;
	data[2] = 0;
	data[3] = m / 2;

	for (int i = 4; i < n; i++) {
		data[i] = 0;
	}
	long long tmp = 0;
	for (int i = 0; i < n - 1; i++) {
		tmp += (data[i] + data[i + 1]);
	}
	cout << tmp << endl;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


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

using namespace std;
//int  mindiv(long long int N) {
//	for(int i = 2; i <= N; i++) {
//		if(N % i == 0) {
//			return i;
//		}
//
//		for(int j = i + 1; j*j <= N; j=j+2){
//			if(N%j == 0){
//				return j;
//			}
//		}
//		return N;
//	}
//}

void fun(long long int& n, long long int m) {

	vector<int> data(n, 0);
	if (n == 2 || n == 3) {
		cout << m << endl;
		return;
	}
	if (n == 4) {
		cout << 2 *(m - m/2) + m/2 << endl;
		return;
	}
	/*data[0] = 0;
	data[1] = m - m / 2;
	data[2] = 0;
	data[3] = m / 2;

	for (int i = 4; i < n; i++) {
		data[i] = 0;
	}
	long long tmp = 0;
	for (int i = 0; i < n - 1; i++) {
		tmp += (data[i] + data[i + 1]);
	}*/
	cout << 2 * (m - m / 2) + 2 * (m / 2) << endl;
	return;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


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

using namespace std;
int  mindiv(long long int N) {
	for(int i = 2; i <= N; i++) {
		if(N % i == 0) {
			return i;
		}

		for(int j = i + 1; j*j <= N; j=j+2){
			if(N%j == 0){
				return j;
			}
		}
		return N;
	}
}

void fun(long long int& n, long long int m) {

	//vector<int> data(n, 0);
	if (n == 2 || n == 3) {
		cout << m << endl;
		return;
	}
	/*data[0] = 0;
	data[1] = m - m / 2;
	data[2] = 0;
	data[3] = m / 2;*/

	/*for (int i = 3; i < n; i++) {
		data[i] = 0;
	}*/
	cout << 2 * (m - m / 2) + 2 * (m / 2) << endl;
	return;
}
int main() {
	int t = 0; cin >> t;
	for(int j = 0; j < t; j++) {
		long long int n = 0, m = 0; cin >> n >> m;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}

		fun(n, m);
	}
	return 0;
}


Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NC200514", "NC200514\NC200514.vcxproj", "{9983A791-A038-40B3-BF9D-1C76685DE902}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Win32 = Debug|Win32
		Release|Win32 = Release|Win32
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{9983A791-A038-40B3-BF9D-1C76685DE902}.Debug|Win32.ActiveCfg = Debug|Win32
		{9983A791-A038-40B3-BF9D-1C76685DE902}.Debug|Win32.Build.0 = Debug|Win32
		{9983A791-A038-40B3-BF9D-1C76685DE902}.Release|Win32.ActiveCfg = Release|Win32
		{9983A791-A038-40B3-BF9D-1C76685DE902}.Release|Win32.Build.0 = Release|Win32
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal


#include<iostream>
using namespace std;
int main(){
	int t,n,m,i,x;
	cin>>t;
	for(i=0;i<t;i++){
		cin>>n>>m;
		if(n==1)x=0;
		else if(n==2) x=m;
		else if(n>=3) x=2*m;
		cout<<x<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==0){
        cout<<0;
    }
    else {
        cout<<2*m;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    if(n==1){
        cout<<0;
    }
    else {
        cout<<2*m;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    cout<<min(2,n-1)*m;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m;
    int t;
    cin>>t;
    while(t--){
           cin>>n>>m;
        cout<<min(2,n-1)*m<<"\n" ;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t, n, m;
    cin >> t;
    for(int i = 0; i < t; i++)
    {
        cin >> n >> m;
        if(n == 1)
        {
            cout << 0 << endl;
        }
        else if(n == 2)
        {
            cout << m << endl;
        }
        else
        {
            cout << m * 2 << endl;
        }
    }
}


#include<cstdio>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n==1){
			printf("0\n");
			continue;
		}
		if(n==2){
			printf("%d\n",m);
		}
		else printf("%d\n",m*2);
	}
}


#include <cstdio>
#include <iostream>

using namespace std;

int main()
{

	int t;

	cin >> t;

	while(t--)
	{
		int n,m;
		cin >> n >> m ;

		if(n == 1) cout << "0" << endl;
		else  if(n == 2)     cout << m    <<endl;
		else  cout << 2 * m << endl;
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <math.h>
#include <ctype.h>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <iomanip>
#define M 100005
const long long N = 998244353;
#define ll long long
using namespace std;
/*
int cmp(const void *a,const void *b)
{
	return *(int *)b-*(int *)a;
}
*/
typedef struct node
{
	int x;
	int y;

}dot;
bool cmp(dot a,dot b)
{
	if(a.y>b.y)return true;
	else if(a.y==b.y)return a.x<b.x;
	else return false;
}
ll gcd(int a,int b)
{
	if(!b)return a;
	else
		return gcd(b,a%b);
}
ll qsm(int a,int b)
{
	long long res=1;
	long long x=a%N;
	while(b)
	{
		if(b&1)res=res%N*x%N;
		x=x*x%N;
		b>>=1;
	}
	return res;
}

/*
bool isnotprime[2100005];
int prime[2100005];
for(int i=2;i<2100000;i++)
	{
		if(!isnotprime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&i*prime[j]<2100000;j++)
		{
			isnotprime[i*prime[j]]=true;
			if(i%prime[j]==0)break;
		}
	}
*/
/*
int next[10000005];
void Next(char *s,int len)
{
	::next[0]=0;
	::next[1]=0;
	for(int i=1;i<len;i++)
	{
		int j=::next[i];
		while(j&&s[i]!=s[j])j=::next[j];
		if(s[i]==s[j])::next[i+1]=j+1;
		else ::next[i+1]=0;
	}
}
*/

void swap(int &a,int &b)
{
	a^=b^=a^=b;
}

int a[200005];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	//freopen("test14.in","r",stdin);
	//freopen("test14.out","w",stdout);

	int t;
	int n,m;
	scanf("%d",&t);
	while(t--){
		int ans;
		scanf("%d%d",&n,&m);
		if(n==1)ans=0;
		else if(n==2)ans=m;
		else ans=2*m;

		printf("%d\n",ans);
	}

	return 0;
}


#include<iostream>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int num;
	cin >> num;
	for (int k = 0; k<num; k++){
		int n, m;
		cin >> n >> m;
		if (n > 2){
			cout << m * 2 << "\n";
		}
		else if (n == 2){
			cout << m << "\n";
		}
		else{
			cout << 0<<"\n";
		}
	}
	//cout << "123";
	//system("pause");
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<climits>
#include<algorithm>
#include<cmath>
typedef long long int ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
      ll a,b;
      cin >> a>>b;
      if(a==1)
      {
        cout<<0<<endl;
        continue;
      }
      if(a==2)
      {
        cout<<b<<endl;
        continue;
      }

        cout<<2*b<<endl;
        continue;

    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#define ll long long

ll t , number , s;

int main ( void )
{
	scanf ( "%lld" , &t );
	while ( t-- ) {
		scanf ( "%lld %lld" , &s , &number );
		if ( s == 1 ) {
			printf ( "0\n" );
		} else if ( s == 2 ) {
			printf ( "%lld\n" , number );
		} else {
			printf ( "%lld\n" , number << 1 );
		}
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		if(n==1)cout<<0<<endl;
		else if(n==2||n==3)cout<<m<<endl;
		else cout<<2*m<<endl;
	}
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		if(n==1)cout<<0<<endl;
		else if(n==2||n==3)cout<<m<<endl;
		else cout<<2*m<<endl;
	}
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		if(n==1)cout<<0<<endl;
		else if(n==2)cout<<m<<endl;
		else cout<<2*m<<endl;
	}
}


#include <iostream>
#include <conio.h>
using namespace std;
int main(){
	int t,n,m;
	cin>>t;
	for(int i=0;i<t;i++){
          n=m=0;
	cin>>n>>m;
         if(n==1){
		cout<<0<<endl;
	}else if(n==2){
		cout<<m<<endl;;
	}else{
		cout<<2*m<<endl;
	}
	}
}


#include<stdio.h>
int main()
{
	int t;
	scanf("%lld",&t);
	while(t--)
	{
	    long long m,n;
	    scanf("%lld %lld",&m,&n);
		if(m==1)
		printf("0\n");
		else if(m==2)
		printf("%lld",n);
		else
		printf("%lld",n*2);

	}

	return 0;
 }


#include<stdio.h>
int main()
{
	int t;
	scanf("%lld",&t);
	while(t--)
	{
	    long long m,n;
	    scanf("%lld %lld",&m,&n);
		if(m==1)
		printf("0\n");
		else if(m==2)
		printf("%lld\n",n);
		else
		printf("%lld\n",n*2);

	}

	return 0;
 }