#include<bits/stdc++.h>
using namespace std;
const int N = 2e7+1;
int a[N], c, d, x;
#define ll long long

void sieve() {
    a[1] = 1;
    for(int i=2; i<N; i++) {
        if(a[i]) {
            continue;
        }
        a[i] = i;
        for(ll j=i*1ll*i; j<N; j+=i) {
            if(!a[j]) {
                a[j] = i;
            }
        }
    }
}
ll cal(ll g) {
    if((x/g+d)%c) {
        return 0;
    }
    int val = (x/g+d)/c;
    int cnt = 0, prev = 0;
    while(val!=1) {
        int minfac = a[val];
        if(minfac!=prev) {
            cnt++;
            prev = minfac;
        }
        val /= minfac;
    }
    return 1ll<<cnt;
}
void solve() {
    ll ans = 0;
    for(int i=1; i*i<=x; i++) {
        if(x%i) {
            continue;
        }
        ans += cal(i);
        if(i*i!=x) {
            ans += cal(x/i);
        }
    }
    cout << ans << endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int t;      cin >> t;
    sieve();
    while(t--) {
        cin >> c >> d >> x;
        solve();
    }
	return 0;
}