import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) class Combination: """ SIZEが10**6程度以下の二項係数を何回も呼び出したいときに使う 使い方: comb = Combination(SIZE, MOD) comb(10, 3) => 120 """ def __init__(self, N, MOD=10 ** 9 + 7): self.MOD = MOD self.__make_factorial_list(N) def __call__(self, n, k): if k < 0 or k > n: return 0 res = self.fact[n] * self.inv[k] % self.MOD res = res * self.inv[n - k] % self.MOD return res def nPk(self, n, k): if k < 0 or k > n: return 0 return self.fact[n] * self.inv[n - k] % self.MOD def nHk(self, n, k): if k == 0: return 1 return self.__call__(n + k - 1, k) def __make_factorial_list(self, N): self.fact = [1] * (N + 1) self.inv = [1] * (N + 1) MOD = self.MOD for i in range(1, N + 1): self.fact[i] = (self.fact[i - 1] * i) % MOD self.inv[N] = pow(self.fact[N], MOD - 2, MOD) for i in range(N, 0, -1): self.inv[i - 1] = (self.inv[i] * i) % MOD return mod = 10 ** 9 + 7 comb = Combination(10 ** 6, mod) def F(k, l): """ comb(i+j, i) for i=0 to k, j=0 to l """ return comb(k+l+2, k+1) T = int(input()) for _ in range(T): H, W = map(int, input().split()) if (H-1)*(W-1) == 0: print(0) continue h = H - 1 w = W - 1 ans = 2 * (h + w - 1) * comb(h + w - 2, h - 1) % mod print(ans)