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