#define LOCAL
//#define GLOBAL
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cassert>
#include<ctime>
#include<utility>
#include<queue>

using namespace std;
int N = 3000005;

int mod = 1000000007;
vector<int>fact(N), ofact(N), obr(N);
int bp(int x, int y)
{
	if (y == 0)
		return 1;
	if (y == 1)
		return x;
	if (y % 2 == 0)
	{
		int t = bp(x, y / 2);
		return (t * 1LL * t) % mod;
	}
	int t = bp(x, y -1);
	return (t * 1LL * x) % mod;
}
void prec()
{
	fact[0] = 1;
	for (int i = 1; i < N; i++)
	{
		fact[i] = (fact[i - 1] * 1LL * i) % mod;
	}
	ofact[N - 1] = bp(fact[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--)
	{
		ofact[i] = (ofact[i + 1] * 1LL * (i + 1)) % mod;
	}
	for (int i = 1; i < N; i++)
	{
		obr[i] = (ofact[i] * 1LL * fact[i-1]) % mod;
	}
}

int slow(int pairs, int np, int to)
{
	int p1 = (to*1LL*obr[to + np + 2 * pairs])%mod, p2= (2*pairs * 1LL * obr[to + np + 2 * pairs]) % mod, p3= (np * 1LL * obr[to + np + 2 * pairs]) % mod;
	long long tt = 1;
	if (pairs > 0)
		tt += p2 * 1LL* ( slow(pairs - 1, np, to+1));
	if (np > 0)
		tt += p3 * 1LL*( slow(pairs, np-1, to));
	return tt % mod;
}

int main()
{
	prec();
	int pairs, np;
	//10^6, 10^6
	int tests;
	cin >> tests;
	for (int tt = 0; tt < tests; tt++)
	{
		int pairs, np;
		cin >> pairs >> np;
		int val = (fact[pairs] * 1LL * fact[pairs]) % mod;
		val = (val * 1LL * ofact[2 * pairs]) % mod;
		val = (val * 1LL * bp(4,pairs)) % mod;
		val= (val * 1LL * (np + pairs * 2 + 1)) % mod;
		val = (val * 1LL * obr[2*pairs+1]) % mod;
		cout << val <<endl;
	}
}