#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long n, m;       cin >> n >> m;       long sum = 0;       if (n == 1 || n == 2) {         if (n == 1)           cout << 0 << endl;         else           cout << m << endl;       } else {         cout << 2 * m << endl;       }     }   }   