#include using namespace std; typedef long long ll; template void check_min(T &a, const T &b){ a = (a < b) ? a : b; } template void check_max(T &a, const T &b){ a = (a > b) ? a : b; } #define all(x) (x).begin(), (x).end() void files(string name){ freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } const ll MOD = 1e9 + 7; ll fast_pow(ll base, ll exp){ if(!exp) return 1ll; if(exp & 1) return fast_pow(base, exp - 1) * base % MOD; ll t = fast_pow(base, exp >> 1); return t * t % MOD; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); files("matrices"); int t; cin >> t; while(t--){ int n, m; cin >> n >> m; ll ans = 1; for(int i = 2; i <= min(n, m); ++i) ans = ans * fast_pow(i + 1, n + m + 1 - 2 * i) % MOD; cout << ans << "\n"; } }