mod = 10 ** 9 + 7 N = 4 * 10 ** 5 + 5 bikkuri = [0] * N bikkuri[0] = 1 gyaku = [0] * N for i in range(1, N): bikkuri[i] = (i * bikkuri[i - 1]) % mod gyaku[N - 1] = pow(bikkuri[N - 1], mod - 2, mod) for i in range(N)[::-1]: gyaku[i - 1] = (gyaku[i] * i) % mod def comb(n, r): if r < 0 or n - r < 0: return 0 return (bikkuri[n] * gyaku[r] * gyaku[n - r]) % mod t = int(input()) for _ in range(t): h, w = map(int, input().split()) h -= 1 w -= 1 ans = 0 num1 = min(h, w) for i in range(1, num1 + 1): j = i - 1 ans += 2 * comb(h - 1, j) * comb(w - 1, j) * (2 * j + 1) ans += comb(h - 1, j) * comb(w - 1, j - 1) * (2 * j) ans += comb(h - 1, j - 1) * comb(w - 1, j) * (2 * j) ans %= mod if h != w: num = min(h, w) ans += comb(num + 1 - 1, num) * comb(num - 1, num - 1) * (2 * num) print(ans % mod)