/* -*- coding: utf-8 -*- * * 1520.cc: No.1520 Zigzag Sum - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_H = 200000; const int MAX_W = 200000; const int MAX_N = MAX_H + MAX_W; const int MOD = 1000000007; /* typedef */ typedef long long ll; /* global variables */ int fs[MAX_N + 1], invfs[MAX_N + 1]; /* subroutines */ int powmod(int a, int n) { // a^n % MOD int pm = 1; while (n > 0) { if (n & 1) pm = (ll)pm * a % MOD; a = (ll)a * a % MOD; n >>= 1; } return pm; } inline int nck(int n, int k) { // nCk % MOD return (ll)fs[n] * invfs[n - k] % MOD * invfs[k] % MOD; } void prepare_fracs(int n) { fs[0] = invfs[0] = 1; for (int i = 1; i <= n; i++) { fs[i] = (ll)fs[i - 1] * i % MOD; invfs[i] = powmod(fs[i], MOD - 2); } } /* subroutines */ /* main */ int main() { prepare_fracs(MAX_N); int tn; scanf("%d", &tn); while (tn--) { int h, w; scanf("%d%d", &h, &w); if (h == 1 || w == 1) puts("0"); else { int a = (ll)nck(h + w - 4, h - 2) * (h + w - 3) % MOD * 2 % MOD; printf("%d\n", a); } } return 0; }