#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define LL long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

class triplet{
    public:
    LL a;
    LL b;
    LL gcd;
};

triplet extended_euclid(LL a,LL b)
{
    if(b==0)
    {
        triplet x;
        x.a=1;
        x.b=0;
        x.gcd=a;
        return x;
    }
    triplet x1=extended_euclid(b,a%b);
    triplet x;
    x.a=x1.b;
    x.b=x1.a-(a/b)*(x1.b);
    x.gcd=x1.gcd;
    return x;
}
LL mod_inverse(LL a, LL m)
{
    LL ans=extended_euclid(a,m).a;
    return (ans%m +m )%m;
}

void solve(){
  int n,s,k;
  cin >> n >> s >> k;
  int gcd = __gcd(n,k);
  int steps_to_move = n - s;
  if (steps_to_move%gcd != 0) {
    cout << "-1\n";
    return;
  }
  
  n /= gcd;
  k /= gcd;
  steps_to_move /= gcd;

  int ans = mod_inverse(k,n);
  ans*= steps_to_move;
  ans %= n;
  ans += n;
  ans %= n;

  cout << ans << "\n";
  
}


signed main(){
  fast;
  int test = 1;
  cin>>test;
  int i=1;
  while(test--){
    solve();
  }
}




#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll t;
  cin >> t;
  while (t--) {
    ll n, a, b;
    cin >> n >> a >> b;

    if (n - a - b < 0) {
      cout << 0 << '\n';
      continue;
    }
    ll ans = ((n - a + 1) * (n - b + 1) - (n - a - b + 1) * (n - a - b + 2) + mod * mod) % mod;
    ans = ans * ans % mod;
    ans = ((n - a + 1) * (n - a + 1) % mod * (n - b + 1) % mod * (n - b + 1) % mod - ans + mod) % mod;
    cout << ans << '\n';
  }

  
  return 0;
}