#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<=n;i++)
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define mii map<ll,ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define endl "\n"
#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":"<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<" : "<<f<<endl
const ll mod = 1e9+7;
#define popcount(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define mem(a,v) memset(a,v,sizeof(a))
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

ll dx[]={-1,0,1,0};
ll dy[]={0,-1,0,1};

ll msum(ll a,ll b,ll m) { return (a%m+b%m)%m; }
ll msub(ll a,ll b,ll m) { return (a%m-b%m)%m; }
ll mpro(ll a,ll b,ll m) { return ((a%m)*(b%m))%m; }
ll m_m(ll a,ll b,ll m);
ll fxp(ll a,ll b,ll m);
void swap(ll &a,ll &b){ ll t=a; a=b; b=t;}

const ll N=2e7+5;
vi prime;
bool check[N];

ll lpf[N];

ll dp[N];

void cal()
{
    for(ll i=1;i<=N;i++)
    {
        check[i]=true;
        lpf[i]=1;
    }
    check[0]=check[1]=false;
    for(ll i=2;i*i<=N;i++)
    {
        if(check[i]==1)
        {
            lpf[i]=i;
            prime.pb(i);
            for(ll j=i*i;j<=N;j+=i)
            {
                if(check[j]!=0)
                    lpf[j]=i;
                check[j]=0;
            }       
        }
    } 

    for(ll i=2;i<N;i++)
    {
        if(check[i])
            dp[i]=1;
        else
        {
            dp[i]=dp[i/lpf[i]]+(lpf[i] != lpf[i/lpf[i]]);
        }
    }
    // ll i;
    // fo(i,10)
    // {
    //     trace3(i,lpf[i],dp[i]);
    //     // cout<<lpf[i]<<" "
    //     // cout<<dp[i]<<" ";
    // }
    // cout<<endl;

}

ll getAns(ll x,ll c,ll d,ll g)
{
    ll p=x/g;
    ll num=p+d;
    if(num%c!=0)
        return 0;
    
    ll z=num/c;

    return 1<<dp[z];

}

void solve()
{
    ll c,d,x;
    cin>>c>>d>>x;

    ll i;

    ll ans=0;
    for(i=1;i*i<=x;i++)
    {
        if(x%i==0)
        {
            ans+=getAns(x,c,d,i);
            if(x/i!=i)
                ans+=getAns(x,c,d,x/i);
        }
    }
    cout<<ans<<endl;
}

int main()
{
    fastio
    int t=1;
    cal();
    cin>>t;
    while(t--)
    {
        solve();   
    }
 return 0;
}
ll fxp(ll a,ll b,ll m) {
    if(b==0)
        return 1;
    if(b%2==0)
        return fxp(m_m(a,a,m),b/2,m);
    return m_m(fxp(a,b-1,m),a,m);
}
ll m_m(ll a,ll b,ll m) 
{
    ll res=0;
    a=a%m;
    while(b)
    {
        if(b&1)
        {
            res+=a; 
            res=res%m;
        }
        a=(a*2)%m;
        b=b/2;
    }
    return res;
}