#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>
#define pdd pair<double, double>
#define pb push_back    
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

using namespace std;

template<class T> void print(T a) {
    for (auto x : a)
        cout << x << ' ';
    cout << '\n';
}

template<class T, class U> inline istream& operator >> (istream& str, pair<T, U> &p) {
    return str >> p.ff >> p.ss;
}

template<class T, class U> inline ostream& operator << (ostream& str, pair<T, U> &p) {
    return str << p.ff << ' ' << p.ss;
}

auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);

struct Siev {
    int MAX_VAL = 1e6 + 5;
    vector<int> lp, pr;

    Siev() {
        
    }

    Siev(int _MAX_VAL) {
        MAX_VAL = _MAX_VAL;
        lp.resize(MAX_VAL + 5);
    }

    void run() {
        for (int i = 2; i <= MAX_VAL; i++) {
            if (lp[i] == 0) {
                lp[i] = i;
                pr.push_back(i);
            }
            for (int j = 0; j < sz(pr) && pr[j] <= lp[i] && i * pr[j] <= MAX_VAL; j++)
                lp[i * pr[j]] = pr[j];
        }
    }

    vector<int> fast_fact(int a) {
        vector<int> res;
        for (int x = a; x != 1; x = x / lp[x]) {
            res.pb(lp[x]);
        }

        return res;
    }

    int num_fact(int a) {
        int ans = 0;
        int last = -1;
        for (int x = a; x != 1; x = x / lp[x]) {
            if (last != lp[x])
                ans++;
            last = lp[x];
        }
        return ans;        
    }
};

Siev siev(3e7);

const ll INF = 1e18;

ll calc(int c, int d, int x, int val) {
    int kek = val + d;
    if (kek % c != 0)
        return 0;
    int p = kek / c;
    if (p == 0)
        return 0;

    int power = siev.num_fact(p);

    ll ans = 1;
    forn (i, power)
        ans *= 2;
    return ans;
}

void solve() {
    int c, d, x;
    cin >> c >> d >> x;

    ll ans = 0;
    for (int i = 1; i * i <= x; i++) {
        if (x % i != 0)
            continue;

        int d1 = i, d2 = x / i;
        ans += calc(c, d, x, d1);

        if (d1 == d2)
            continue;
        ans += calc(c, d, x, d2);
    }
    cout << ans << '\n';
}   

signed main() {
    //freopen("test.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    siev.run();

    int t = 1;
    cin >> t;
    forn (i, t) {
        solve();
    }

    return 0;
}