#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 2e7 + 1;
int a[N];
long long c, d, x;

long long fun(int gc) {
    long long cur = x + gc * d;
    if (cur % c != 0 || (cur / c) % gc != 0) {
        return 0;
    }
    long long lc = cur / c;
    lc /= gc;
    return (1LL << a[lc]);
}

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

    long long ans = 0;
    for (int i = 1 ; 1LL * i * i <= x ; i++) {
        if (x % i == 0) {
            ans += fun(i);
            if (1LL * i * i != x) {
                ans += fun(x/i);
            }
        }
    }

    cout << ans << "\n";
}

int32_t main() {
    fast;

    for (int i = 2 ; i < N ; i++) if (a[i] == 0) {
            a[i] = 1;
            for (int j = 2 * i ; j < N ; j += i) {
                a[j]++;
            }
        }

    int t = 1;
    cin >> t;
    while (t--)  solve();
}