#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
const ll M=20000005;
ll nopd[M];
void pre(){
	for(ll i=2;i<M;i++){
		if(nopd[i]==0){
			for(ll j=i;j<M;j+=i) nopd[j] += 1;
		}
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	pre();
	ll t;
	cin>>t;
	while(t--){
		ll c,d,x;
		cin>>c>>d>>x;
		ll ans=0;
		for(ll i=1;i*i<=x;i++){
			if(x%i==0){
				if(i!=x/i){
					ll num = i+d;
					if(num%c==0) ans += pow(2, nopd[num/c]);
				}
				ll num = x/i +d ;
				if(num%c==0) ans += pow(2 , nopd[num/c]);
			}
		}
		cout<<ans<<"\n";
	}
	
	return 0;
}
