#include #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair P; typedef pair PP; typedef vector > Graph; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e18; #define debug(v) cout<<#v<<": ",prt(v); template inline void prt(pair p){cout<<"("< inline void prt(tuple p){cout<<"("<(p)<<", "<(p)<<", "<(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template inline void prt(vector v){cout<<'{';for(ll i=0;i inline void prt(vector >& vv){ for(const auto& v : vv){ prt(v); } } template inline void prt(deque v){cout<<'{';for(ll i=0;i inline void prt(map v){cout<<'{';ll c=0;for(auto &p: v){cout< inline void prt(unordered_map v){cout<<'{';ll c=0;for(auto &p: v){cout< inline void prt(set v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template inline void prt(multiset v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} // auto mod int // depends on Template const int mod = 1000000007; //const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(){ ll s; cin >> s; rep(test,s){ ll n,m,x; cin >> n >> m >> x; mint ans = 0; ans += modpow(m+1,n); ans += modpow(m-1,n); ans /= 2; cout << ans << endl; } return 0; }