#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define N 20000001
vector<int> seive(N,0);
int calc(ll x){
   
   //cout<<"x "<<x;
   ll no=0;
   while(x!=1){
            int temp=0;
             int div=seive[x];
             while(div==seive[x]){
                 x=x/div;
             }
             no++;
   }
   return (1<<no);
}
void solve(){
    
    int c,d,x;
    cin>>c>>d>>x;
    ll ans=0;
    for(ll i=1;i*i<=x;i++){
        
        if(x%i==0){
             
             ll no1=i;
             ll no2=x/i;
             ll fact1=0;
             ll fact2=0;
             if((no1+d)%c==0){
                 ll v=(no1+d)/c;
                 fact1=calc(v);
             }
             if((no2+d)%c==0){
                 ll v=(no2+d)/c;
                 fact2=calc(v);
             }
             if(no1!=no2){
                 ans+=(fact1+fact2);
             }
             else{
                 ans+=fact1;
             }


        }
    }
   cout<<ans<<endl;


}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    for(int i=1;i<N;i++){
        seive[i]=i;
    }
    for (int i=4;i<N;i+=2) 
        seive[i]=2;

    for (int i=3; i*i<N; i++) 
    { 
        if (seive[i] == i) 
        { 
            for (int j=i*i; j<N; j+=i) 
                if (seive[j]==j) 
                    seive[j] = i; 
        } 
    }    

    while(t--){
         solve();
    }
}