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

const int inf  = 1e18+9;
const int mod  = 1e9+7;
const int maxn = 2e7+8;

int c, d, x, dv[maxn], rec[maxn];

void solve() {
    int i, j, res, ans = 0, dc = 0;
    cin >> c >> d >> x;
    for (i = 1; i * i < x; i++) if (x % i == 0) {
        dv[++dc] = i; dv[++dc] = x / i;
    }
    if (i * i == x) dv[++dc] = i;
    for (j = 1; j <= dc; j++) {
        res = (x / dv[j] + d);
        if (res % c == 0) ans += rec[res / c];
    }
    cout << ans << endl;
}

signed main() {
    int i, j;
    for (i = 1; i < maxn; i++) rec[i] = 1;
    for (i = 2; i < maxn; i++) if (rec[i] == 1) {
        for (j = i; j < maxn; j += i) rec[j] *= 2;
    }
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; cin >> t;
    while (t--) solve();
    return 0;
}

