#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll prime[20000005];
ll power(ll a,ll b){
	if(b==0) return 1;
	if(b==1) return a;
	ll x = power(a,b/2);
	if(b%2)
		return x*x*a;
	return x*x;
}
int solve(){
	ll c,d,x; cin>>c>>d>>x;
	vector <int> factors;
	for(int i=1;i*i<=x;i++){
		if(x%i ==0 ){
			if(x/i != i)
				factors.push_back(x/i);
			factors.push_back(i);
		}
	}
	ll beta = 0,hcf , lcm,ans= 0;
	for(auto alpha : factors){
		if((alpha * d + x)%(alpha * c)==0){
			beta = (alpha * d + x)/(alpha * c);
// 			deb(prime[beta])
			ans+=power((ll)2,prime[beta]);
			// hcf = alpha;
			// lcm = beta * alpha;	
			// deb2(alpha,beta)
			// deb(ans)
			// deb2(hcf,lcm)
		}
	}
	cout<<ans<<"\n";
	// alpha  = gcd(a,b)
	// beta = a*b/ (gcd(a,b)^2)
	// @#c = @d+x
	return 0;
}
int main(){
	fast
	ll i,j;
	prime[0] =0;
	prime[1] =0;
	for(i  = 2;i<= 20000002 ; i++ ){
		if(prime[i] == 0){
			for( j =i;j<=20000002;j+=i){
				prime[j]++;
			}
		}
	}
	int t; cin>>t;
	while(t--){
		solve();
	}
}