#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
#define mxe(a) max_element(all(a)) 
#define mne(a) max_element(all(a))  

// #define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const int N = 2e7 + 1 ;
int sv[N] ; 

void pre() {
    for(int i = 2 ; i < N ; i += 2) sv[i] = 2 ; 
    for(int i = 3 ; i < N ; i += 2) {
        if(sv[i] == 0) {
            for(int j = i ; j < N ; j += i) {
                if(!sv[j]) sv[j] = i ; 
            }
        }
    }
}

void solve(int test) {

    int c, d, x; 
    cin >> c >> d >> x;  
    ll ans = 0 ; 
    
    for(int i = 1 ; i * i <= x ; ++i) {
        if(x%i == 0) {
            int g = i ; 
            if((x/g+d)%c==0) {
                int AB = (x/g + d)/c ; 
                int cnt = 0, p = 0 ; 
                while(AB != 1) {
                    if(p == 0) cnt ++, p = sv[AB], AB /= sv[AB] ; 
                    else {
                        if(p != sv[AB]) ++cnt ; 
                        p = sv[AB] ; 
                        AB /= p ; 
                    }
                }
                ans += (1ll << (cnt)) ; 
            }
            if(i*i == x) break ; 
            g = x/i ; 
            if((x/g+d)%c==0) {
                int AB = (x/g + d)/c ; 
                int cnt = 0, p = 0 ; 
                while(AB != 1) {
                    if(p == 0) cnt ++, p = sv[AB], AB /= sv[AB] ; 
                    else {
                        if(p != sv[AB]) ++cnt ; 
                        p = sv[AB] ; 
                        AB /= p ; 
                    }
                }
                ans += (1ll << (cnt)) ; 
            }
        }
    }

    cout << ans << nl ; 
}   
 
int32_t main() {

    pre() ; 

    fast;
    int t = 1;
    cin>>t;
    rep(i,1,t+1) {
        solve(i) ;
    }
 
    // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    return 0;
}