#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, n1, n2, cnt = 0, t;
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d %d", &n1, &n2);
    if (n1 < 2)
      printf("0\n");
    else if (n1 > 2)
      printf("%d\n", 2 * n2);
    else
      printf("%d\n", n2);
  }
  return 0;
}
