# python3 # N*M翻牌, 80% case t = int(input()) res=[] for i in range(t): N, M = map(int, input().split()) if N == 1: if M == 1: res.append(1) else: res.append(M - 2) elif M == 1: if N == 1: res.append(1) else: res.append(N - 2) if N>=2 and M>=2: res.append((N-2)*(M-2)) for i in res: print(i)