#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
#define int ll
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;

vi isPrime;
vi fact;

void sieve(){
    int MAXN = 2e7+10;
    isPrime.resize(MAXN);
    fact.assign(MAXN, -1);
    for (int l = 0; l < MAXN; ++l) isPrime[l]=l;
    for (int i = 2; i*i <= MAXN; ++i) {
        if (isPrime[i]!=i) continue;
        int d = i*i;
        for (int j = d; j < MAXN; j+=i) {
            isPrime[j] = isPrime[j] == j ? i: isPrime[j];
        }
    }
}
int count_divs(int k){
    if (fact[k] != -1) return fact[k];
    int kk = k;
    int ans = 0;
    while (k != 1){
        ans++;
        int d = isPrime[k], f = 0;
        while (k%d == 0)f++, k/= d;
    }
    return fact[kk] = ans;
}

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T=1, c, d, x;
    cin >> T;
    sieve();
    while (T--){
        cin >> c >> d >> x;
        int ans = 0;
        for (int g = 1; g*g <= x; ++g) {
            if (x%g) continue;
            int p = x/g + d;
            if (p%c == 0) {
                int q = p / c;
                ans += (1ll << count_divs(q));
            }
            int G = x/g;
            if (G == g) continue;
            p = x/G + d;
            if (p%c) continue;
            int q = p/c;
            ans += (1ll << count_divs(q));
        }
        cout << ans << "\n";
    }
}