#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;


#pragma GCC target("popcnt")  //https://godbolt.org/z/yQv94Y 

typedef long long int ll;
typedef unsigned long long int  ull;
typedef long double ld;

const ld pi = 4.0*atan(1.0);
#define xlr8 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(10); cout<<fixed


typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// T.insert(a), T.erase(a), T.size()
// T.order_of_key(a) -- number of elements strictly less than a
// *T.find_by_order(k) -- k-th element in increasing order

struct Timer
{   chrono::time_point<chrono::high_resolution_clock> start , end; chrono:: duration<float> dur;
    Timer(){start = chrono::high_resolution_clock::now();}
    ~Timer(){   end = chrono::high_resolution_clock::now(); dur = end - start;  cout<<"\nTime Elapsed : " <<dur.count() << " s\n";  }
};


template<typename T>
void getVec(vector<T>& a , int st, int en)
{
    int dif = (en > st ? 1 : -1);
    for(int  i = st ; i!= en ; i+= dif)
        cin>>a[i];
}
template<typename T>
void getVecPair(vector<pair<T , T > >& a , int st, int en)
{
    int dif = (en > st ? 1 : -1);
    for(int  i = st ; i!= en ; i+= dif)
        cin>>a[i].first>>a[i].second;
}


//76149
template<int D, typename T> 
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};


// const int MAX = 1000;
// Vec<2 , int > dp(MAX + 1, MAX + 1, -1);

ll gcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

int main()
{
    xlr8;
    int testCases  = 1;
    cin>>testCases;
    while (testCases--)
    {
        ll n , s , k;
        cin>>n>>s>>k;
        s = n -s;
        ll d = __gcd(k , n);
        k/=d;
        n/=d;
        if(s%d!= 0)
            {
                cout<<"-1\n";
            }
        else 
            {
                s/=d;
                ll x, y;
                ll g = gcd(k, n, x, y);
                if (g != 1) 
                {
                    cout << "-1\n";
                }
                else 
                {
                    x = (x % n + n) % n;
                    x = (x*s)%n;
                    cout << x <<"\n";
                }
            }
        
    }
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const int mod = 1000000007;

ll T, n, a, b;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> T;
	while (T--) {
		cin >> n >> a >> b;
		if (n < a + b) {
			cout << 0 << endl;
			continue;
		}
		if (a < b)swap(a, b);
		ll k = n - a + 1;
		ll p = n - a - b + 1;
		ll ans = (n - a + 1)*(n - a + 1) % mod*(n - b + 1) % mod*(n - b + 1) % mod;
		ll x = (2 * (b*(b - 1) / 2 + (k - b)*(b - 1)) + k * (a - b + 1)) % mod;
		ans = (ans - x * x%mod + mod) % mod;
		cout << ans << endl;
	}
}