#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e3 + 10;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int 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
      cout << (n / 2) * 2 * m / (n / 2) << "\n";
  }
  return 0;
}
