#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
#define fo(i,a,b) for(int i=a;i<b;i++)
#define ro(i,a,b) for(int i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define sc(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pr(n) printf("%d\n",n)
#define pl(n) printf("%lld\n",n)
#define prs(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)
using namespace std;

ll GCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1LL;
		y = 0LL;
		return a;
	}
	ll x1, y1;
	ll d = GCD(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * 1LL * (a / b);
	return d;
}
void solve()
{
	ll n, s, k;
	sl(n), sl(s), sl(k);
	ll x, y;
	ll gc = __gcd(n, k);
	if (s % gc) {
		pl(-1LL);
	}
	else {
		// y->loops x->moves x*k+s=y*n => (x*k-y*n=-s)
		n /= gc, s /= gc, k /= gc;
		gc = GCD(k, n, x, y);
		ll mod_inv = (x % n + n) % n; // k inverse
		ll ans = ((-s * mod_inv) % n + n) % n;
		pl(ans);
	}
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	scanf("%d", &t);
	while (t--) {
		solve();
	}

}
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long 
#define int long long 
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
//#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back 

#define min(a,b) (a<b?a:b) 
#define forn(n) for(ll i=0;i<n;i++) 
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
#define pii pair<int,int>
const int mod = 1e9 + 7;
const int N=1e6+1;
const int N2 = 1e5+1;
#define pi 3.141592653589793238


using namespace std;
vector<int>v(100002);
unsigned long long power(unsigned long long x, 
                                  int y, int p)
{
    unsigned long long res = 1; 
 
    x = x % p; 
 
    while (y > 0) 
    {
        if (y & 1)
            res = (res * x) % p;
 
        y = y >> 1; 
        x = (x * x) % p;
    }
    return res;
}
 
bool key(string s, int b,int m)
{
		int k = 0;
		int n = s.size();
	for(int  i=0; i<s.size(); i++)
	{
		if(pow(b,n-1-i)<0)
		return false;
		k+=s[i]*pow(b,n-1-i); 
	}
	
	
	return (k>m);
}

int bsa(int low, int high, int m, string s) 
{ 
    int mid; 
  int ans;

 
    while (low < high) { 
        mid =  (high + low) / 2; 
  
//  cout<<mid<<endl;
       
        if ( key(s,mid,m)) { 
          high = mid;
           
        } 
  
      
        else { 
           low = mid+1; 
        } 
        
        
    } 
  
 
    return low; 
} 

int ordertrip(int n)
{
int c =0;
for(int i=1; i*i<=n; i++)
{
	if(n%i==0)
	{
		if(i==n/i)
		{
			c++;
		}
		else
		{
			c+=2;
		}
	}
}
return c;

}

  
void solve()
{
int k;
cin>> k;
int ans = 0;

vector<int>dp(k+1);
dp[1] = 1;
for(int i =2; i<=k;i++)	
{
	dp[i] = dp[i-1] + ordertrip(i);
}
for(int i=1; i<=k; i++)
{

		ans+= dp[k/i];
	
}
cout<<ans;

	}
signed  main()
{
IOS;



//memset(dp,-1,sizeof(dp));
//  freopen("input.txt","r",stdin);
//  freopen("new.txt","w",stdout);
 int t = 1;
//cin>>t;

 while(t--)
 {
	IOS;
 	solve();
 	cout<<endl;
 }
 

 }

//cccccccccccccccccccccccccccccccccccccccc

	
