#include <bits/stdc++.h>

#define ll long long
using namespace std;

#ifndef ONLINE_JUDGE
clock_t prostart = clock();
#endif

void solve();

void files() {
#ifndef ONLINE_JUDGE
    freopen("../data.in", "r", stdin);
    freopen("../data.out", "w", stdout);
#endif
    solve();
#ifndef ONLINE_JUDGE
    cout << "运行时间:" << 1.0 * (clock() - prostart) << "ms" << "\n";
#endif
}

int main() {
    std::ios::sync_with_stdio(false);
    files();
}

const ll maxn = 2e7 + 7;

ll p[maxn], tot; //* p[0] = 2,p[1] = 3... tot为素数个数
bool vis[maxn]; //* vis[i] == 0 -> i为素数

ll t, n, c, d, x, cnt[maxn];

void init(int n = maxn - 1) // 1e7 -> 125ms
{
    for (int i = 2; i <= n; i++) {
        if (!vis[i])
            p[tot++] = i;
        for (int j = 0; j < tot; j++) {
            if (p[j] * i > n)
                break;
            vis[p[j] * i] = 1;
            if (i % p[j] == 0)
                break;
        }
    }
    for (ll i = 0; i < tot; i++) {
        ll now = p[i];
        for (ll mdf = 1; mdf * now < maxn; mdf++)
            cnt[mdf * now]++;
    }
}

ll solve(ll gc, ll lc) {
    if (lc % gc)
        return 0;
    if (lc == gc)
        return 1;
    ll pp = lc / gc;
    return (1LL << cnt[pp]);
}


void solve() {
    cin >> t;
    init();
    while (t--) {
        cin >> c >> d >> x;
        ll ans = 0, h = sqrt(x);
        for (ll gc = 1; gc <= h; gc++) {
            if (x % gc)
                continue;
            ll gc1 = gc;
            if ((x + gc1 * d) % c == 0) {
                ll lm = (x + gc1 * d) / c;
                ans += solve(gc1, lm);
            }
            gc1 = x / gc;

            if (gc1 == gc)
                continue;
            if ((x + gc1 * d) % c == 0) {
                ll lm = (x + gc1 * d) / c;
                ans += solve(gc1, lm);
            }
        }
        cout << ans << endl;
    }
}
