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