#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef long long ll;
const int maxn=2e7+5,inf=0x3f3f3f3f,mod=1e9+7;
const int eps=1e-6;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n;
int c,d,x;
int prime[maxn],cnt;
bool isprime[maxn];
int sum[maxn];
void getprime(int n){
    // O(n)计算所有元素的质因子个数
    for(ll i=2;i<=n;i++){//开ll因为后面要计算i*prime[j]
        if(!isprime[i]){
            prime[++cnt]=i;
            sum[i]=1;
        }
        for(int j=1;j<=cnt&&i*prime[j]<=n;j++){
            isprime[i*prime[j]]=1;
            if(i%prime[j]==0){
                sum[i*prime[j]]=sum[i];
                break;
            }else{
                 sum[i*prime[j]]=sum[i]+1;
            }
        }
    }
}
ll get(int gcd){
//    cout<<gcd<<endl;
    if(1ll*(x+1ll*d*gcd)%c!=0){
        return 0;
    }else{
        ll lcm=1ll*(x+1ll*d*gcd)/c;
        if(lcm%gcd==0)
        return (1ll<<sum[lcm/gcd]);
        return 0;
    }
}
signed main(){
    getprime(2e7);
    int _; scanf("%d",&_);
    while(_--){
        ll ans=0;
        scanf("%d%d%d",&c,&d,&x);
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                ans+=get(i);
                if(i*i!=x){
                    ans+=get(x/i);
                }
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}
