import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int num = sc.nextInt();
        for(int i = 1; i <= num; i++){
            long n = sc.nextLong();
            long m = sc.nextLong();
            long s ;
            if(n == 1 && m == 1){
                s = 1;
            }else if(n == 1){
                s = m - 2;
            }else if(m == 1){
                s = n - 2;
            }else{
                s = (n - 2) * (m - 2);
            }
            System.out.println(s);
        }

    }
}